> No, don't know Delphi-Talk
> Yes, I am worried about the memory allocation stuff 
> Yes, and fragmentation and 
> Yes, I use a lot of string stuff
> So how can I deal efficiently with strings?

It isn't really any issue solely of strings per se.  It's more about
understanding what is happening behind the scenes and when and how the
things you do in the language result in memory allocations and deallocations
and then determining if the task at hand is large or significant enough to
warrant a better approach. 

If you use ansistrings, normally the default Delphi string, then they're
dynamic.  What does this mean?  You must understand this.  Thus, unless you
take steps to the contrary, everytime you simply assign new values to such a
string, allocations and deallocations take place.  Straight-forward.  

The only alternative to this is to do things the way we used to, handle the
allocation yourself.  Ex. Null-terminated strings, or more precisely, arrays
of chars, were important immediately because one could allocate once, a
large but reasonable array, write new data to the array of chars at any
time, stop by adding an ending null and never worry about junk data, never
worry about zeroing first, or clearing old data.  As long as what you needed
fit inside your initial allocation, you used that array over and over
without worry.  Oh you might have to write character by character, so macros
developed, null-terminated handlers, etc.  But you could minimize
allocations.  

Of course, there are reasons to prefer dynamic arrays as well.  But
certainly not when one knows ahead of time that might involved a zillion
repetitive alloc/dealloc procedures.

Strings or arrays of whatever, lists of records or other binary data, it
makes no difference.  It's simply a  matter of understanding how to use,
request and release memory efficiently for what you're wanting to do.

With more efficient handling comes more work.  You have to decide the
trade-offs.  As the example that lead to this discussion demonstrated, the
down-side can be as bad as being literally dysfunctional; the upside can be
a performance boost beyond expectations.  


Regards,

------------------------------------------------------------------------
 Jim Burns, <mailto:[EMAIL PROTECTED]>
   Technology Dynamics
   Pearland, Texas  USA 
   281 485-0410 / 281 813-6939

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to