[DGD] LWO

bart at wotf.org bart at wotf.org
Sat Aug 8 16:19:58 CEST 2015


An example LWO can be found at:

http://wotf.org/downloads/lpc/kvset.c

It should work on gurbalib directly (and with little or no modification on
about every other lib).

It implements a variation on the mapping type that adds support for &, | and -
operators.

Bart

On Sat, 8 Aug 2015 12:05:05 +0200, bart wrote
> Creating an LWO is easy:
> 
> object src;
> object lwo;
> 
> src = find_object( "/path/to/some/object" );
> lwo = new_object( src );
> 
> lwo will be the lightweight object, src is a blueprint object used 
> as a template for the lwo.
> 
> Note that an object does not have to do anything special to be 
> usable as lwo, but there are some differences between a clone of a 
> blueprint object and an lwo:
> 
> Very important: lightweight objects do not get destructed explicitly,
>  they simply are forgotten when nothing references them anymore. 
> This means (very important if you are trying to do any kind of 
> object management or data storage on destruct) there will be NO 
> calls to the lwo informing it that it is going to be destructed. 
> This is a simple fact and not something that you can code your way 
> around, it is a consequence of the nature of LWOs.
> 
> LWOs can *NOT* have call_outs. Again, this is a consequence of the 
> nature of LWOs. Do not use LWOs for code that must use call_outs or 
> move the call_outs to some other bit of code not in an LWO.
> 
> LWOs are kept in the storage space of the object that created them 
> (did the call to new_object()). ALL the things that apply to arrays 
> and mappings that are passed by reference from one object to another 
> also apply to LWOs. This means they will only be shared until the 
> end of the execution round, after which a copy will be made and both 
> objects involved will end up having their own copy of the LWO.  For 
> example, you might want to keep track of some centralized counter 
> for something. You decide to stick this in some object, and let 
> everything that needs this counter call the object. So far so good,
>  and this works with blueprints (as you can simply use find_obect()
>  and are guaranteed to end up at that blueprint) or clones (you have 
> to pass the object reference to code that needs it). Doing this with 
> an LWO however may or may not work depending on exactly how you 
> implement this: - pass lwo reference to other object, which uses it 
> to reference the counter and then forgets it, all in the same 
> execution round: this works - pass lwo reference to another object 
> which stores it and then later on (as the result of a call_out or 
> other user action) tries to use it: this will not work as expected 
> as the LWO is no longer the one that was stored originally, it is a 
> copy of it.
> 
> Also important, LWOs support features that regular clones do not, especially
> operator overloading (see the git commit log for dgd, look for the keyword
> operator).
> 
> Anyway, there are things for which LWOs are an absolutely brilliant 
> solution, things like building advanced data types (for example 
> mappings that can contain a lot more then 16384 key/value pairs),
>  but also things for which they are a very cumbersome solution that 
> is best be avoided.
> 
> So.. creating them is easy, making good use of them however requires 
> some more careful thought really, they are not 'just an alternative 
> for clones', rather, they are something totally different then 
> clones, and generally things that need clones cannot easily be done 
> with LWOs and the other way around.
> 
> Bart.
> 
> On Sat, 08 Aug 2015 03:33:39 -0400, Littlefield, Tyler wrote
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> > 
> > Hello all:
> > I've been looking for examples. Is there a syntax for creating an 
> > LWO? Any help appreciated. Thanks, - -- Take care, Ty twitter: @sorressean
> > web:http://tysdomain.com
> > pubkey: http://tysdomain.com/files/pubkey.asc
> > -----BEGIN PGP SIGNATURE-----
> > Version: GnuPG v2
> > 
> > iQEcBAEBAgAGBQJVxbDTAAoJEAdP60+BYxejpxwH/0DDz+OVTixfxpSa/IFzohUP
> > Y4XoPZxLsk1VQE2HhI1PBBau0tKDezpEGbhYYaM/EvseQ3OuwmkyNwUQlStpCyDd
> > HBManyxOSK0u6mOWkkImtXfCQEoovmzPW1CN6+9rzqYyMlYk0vq+I7E1y9AnoNTa
> > KyDTuIMtgDuNx0IBVBv/ilIegNtToaUjlYufK9by5vOjKfrit18CiT49NV/xdulV
> > u2XmdP3RGaL0UkWnORWT/pBzSksrq250Xqz5QJDfphugR0K/BL8qI0RyfDG/9edK
> > XZ7VHuVSiCJZYVfh8eFVeJ5KfUqVqFMMemMG7446+xf0NtMRcwJkkOjraSSky/M=
> > =mV3K
> > -----END PGP SIGNATURE-----
> > ____________________________________________
> > https://mail.dworkin.nl/mailman/listinfo/dgd
> 
> --
> http://www.flickr.com/photos/mrobjective/
> http://www.om-d.org/
> 
> ____________________________________________
> https://mail.dworkin.nl/mailman/listinfo/dgd


--
http://www.flickr.com/photos/mrobjective/
http://www.om-d.org/




More information about the DGD mailing list