swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Serialization


From: Marcus G. Daniels
Subject: Re: Serialization
Date: 28 Feb 2000 14:08:48 -0800
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4

>>>>> "JB" == Mail Lists <address@hidden> writes:

JB> Can it easily be used to make a deep
JB> copy of an object? My swarm agents contain a binary tree, and I
JB> was looking for a quick and dirty deep copy of agents (several
JB> objects including the tree).

In 2.1 (e.g. approx. the latest snapshot), the Lisp Archiver caches
expressions until an explicit `sync' is done.  With HDF5 there really
is a HDF5 transaction made.  The idea is to get rid of the need for
registerClient: and updateArchiver: -- both Lisp and HDF5 transactions
can be considered immediate.  For example, the code below creates no file,
yet the object is copied by deep-serialization.

#import <simtools.h> // initSwarmBatch
#import <defobj/Create.h> // CreateDrop

@interface Node: CreateDrop
{
  unsigned sn;
}
+ create: aZone setSn: (unsigned)sn;
- (void)describe: stream;
@end

@implementation Node
+ create: aZone setSn: (unsigned)theSn
{
  Node *node = [super createBegin: aZone];

  node->sn = theSn;
  return node;
}

- (void)describe: stream
{
  [stream catC: "[Node sn: "];
  [stream catUnsigned: sn];
  [stream catC: "]"];
}
@end

@interface Tree: CreateDrop
{
  id left, right;
}
+ createBegin: aZone;
- (void)describe: stream;
@end

@implementation Tree
+ createBegin: aZone
{
  Tree *obj = [super createBegin: aZone];

  obj->left = [Node create: aZone setSn: 1];
  obj->right = [Node create: aZone setSn: 2];
  return obj;
}

- (void)describe: stream
{
  [stream catC: "Tree: ["];
  [stream catC: "left: "];
  xprint (left);
  [stream catC: " right: "];
  xprint (right);
  [stream catC: "]"];
}
@end

@interface Agent: CreateDrop
{
  id tree;
}
@end

@implementation Agent
+ createBegin: aZone
{
  Agent *obj = [super createBegin: aZone];

  obj->tree = [Tree create: aZone];
  return obj;
}

- (void)describe: stream
{
  [stream catC: "Agent: ["];
  [stream catPointer: self];
  [stream catC: " "];
  xprint (tree);
  [stream catC: "]\n"];
}
@end

int
main (int argc, const char **argv)
{
  initSwarmBatch (argc, argv);

  {
    id agent;
    
    agent = [Agent create: globalZone];
    xprint (agent);
    [lispAppArchiver putDeep: "agent" object: agent];
    agent = [lispAppArchiver getObject: "agent"];
    xprint (agent);
  }
  return 0;
}

/*
Local Variables:
compile-command: "$SWARMHOME/bin/libtool-swarm --mode=link gcc 
-DAPPNAME=archiveTree -o archiveTree -Wall -Werror -g -Wno-import 
-I$SWARMHOME/include/swarm -L$SWARMHOME/lib/swarm archiveTree.m -lswarm -lobjc"
End:
*/

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]