How can I use array with string?
Please explain and show me the examples.
Posted on 2006-05-29 03:40:12 by ch3cooli
it is short question but too many variances of answer :) what for you plan to use it? what estimated max size of them and amount? should be it static or dinamic (sorting, editing, adding or deleting)?
in general it can be organized like:
1.simpliest (good for few short strings) - allocate space in memory of STRING_SIZE * STRING_NUMBER (eg. 260 and 16) and store pointer to str_array var. then string No.X can be found as +X*STRING_SIZE (X - zero-based).
2.2 arrays - 1-st array has strings, 2-nd - pointers to each string - very fast for sorting, less memory wasting, less good for string modification.
3.linked list - each element contains string and pointer to next string - slow to search, but has no additional arrays. simpliest example: sequence of pascal strings - string length in the string header is offset to the next string (but then impossible keep strings in random sequence)...
Posted on 2006-05-29 04:40:05 by Shoo

2.2 arrays - 1-st array has strings, 2-nd - pointers to each string - very fast for sorting, less memory wasting, less good for string modification.

I would say one array is enough - with pointers to strings in memory. Strings do not have to occupy a continuous memory region, only the array of pointers does.
Posted on 2006-05-29 05:15:40 by Morris
Again, it matters how many, and what expected size.
Allocating a lot of small blocks of memory is a bad idea, if you use heap memory it leads to fragmentation (16 byte alignment) and if you use virtual memory its massively wasteful (minimum memory actually allocated per string is 'granularity' usually 4kb).
So just allocating a bunch of strings and then keeping pointers is a really crap idea, although there is one possible means by which this may be viable, which is to use the SysAllocString api function (I'm pretty sure this has a memory manager behind it).
Posted on 2006-05-29 06:37:03 by Homer
ch3cooli,


How can I use array with string?
Please explain and show me the examples.


    OK, look at the attached zipped file.  It contains a partial source file that gives several examples of how to make an array of string addresses that point to variable length strings, with no padding to the length of the longest string.  A partial listing is enclosed to show how it assembles.  And finally the program itself that shows what it looks like with an application.  Basically you let MASM do the work.  All you need do is tell MASM what to do.  Ask if you have any questions.  Ratch
Attachments:
Posted on 2006-06-01 22:13:44 by Ratch