At 5:58 +0200 6/7/05, Frank Heckenbach wrote:
Peter N Lewis wrote:
I often need to store a lot of strings, and don't want to waste the space allocated to a String(255) for each one. With "short" strings, I just allocate memory (with the Mac system NewPtr routine, not with the Pascal New routine) for Length(s)+1 bytes, and then BlockMove the string in. This has the advantage that the string can be references as just Str255Ptr(s)^ (sometimes the size needs to be aligned to 2 or 4 bytes, depending on the platform).
I could do the same thing with GPC's Schema String(255), but I'd have to pack them in, and then unpack them out to a temporary variable to access them, I could not access them in place in the packed data block.
I presume there are clever ways to do such things in GPC/EP? What would be the options for packing strings into a block of memory and yet still having them usable?
var p: ^String;
New (p, ActualLength);
I'm always hesitant to use Pascal's New in case it does weird things like many Pascals do to support Mark/Release/etc. It appears that GPC calls straight through to malloc/free, with little overhead and no messing around unless Mark/Release procedures are called.
No type-casts, hand-made size computations, worries about alignment or other dirty tricks necessary. That's one of the nice things about schemata (of which strings are a special case).
Indeed, that does look to be a nice solution - I'm looking forward to using all the GPC/EP goodness once I escape from CW, but first I have to get there! 20 more units to go until the fun begins. Peter.