N
nebiyou1
I am trying to implement a simple memory pooling (simple segregated
storage) for character strings (char*) of fixed size. I am running into
some issues, however.
Here is an oversimplified example:
The following allocates a space to hold chunk number of char's.
It then builds a link list and adds the chunks to the list.
std::size_t chunk = 10;
char* array = alloc_mem.allocate(chunk);
for(size_t i=0;i!=chunk;++i)
add_to_freelist(&array);
at the end of this we will have sometn like
[char0] [char1] [char2] ... [char9]
If char is replaced by T, I understand I can use this for any object
type T. (the above example can be found on 761 of C++ primer 4th
edition)
Now, I would like to do something similar for character strings instead
of characters. In other words, given the cstring size, I would like to
allocate space to hold chunk number of cstrings with the given size. If
the size is 3, for instance
[char0[3]] [char1[3]] [char2[3]]... [char9[3]]
How do I do this? Can you please explain using the example I posted
above.
Please help!
FYI: on simple segregated storage
http://www.boost.org/libs/pool/doc/concepts.html
storage) for character strings (char*) of fixed size. I am running into
some issues, however.
Here is an oversimplified example:
The following allocates a space to hold chunk number of char's.
It then builds a link list and adds the chunks to the list.
std::size_t chunk = 10;
char* array = alloc_mem.allocate(chunk);
for(size_t i=0;i!=chunk;++i)
add_to_freelist(&array);
at the end of this we will have sometn like
[char0] [char1] [char2] ... [char9]
If char is replaced by T, I understand I can use this for any object
type T. (the above example can be found on 761 of C++ primer 4th
edition)
Now, I would like to do something similar for character strings instead
of characters. In other words, given the cstring size, I would like to
allocate space to hold chunk number of cstrings with the given size. If
the size is 3, for instance
[char0[3]] [char1[3]] [char2[3]]... [char9[3]]
How do I do this? Can you please explain using the example I posted
above.
Please help!
FYI: on simple segregated storage
http://www.boost.org/libs/pool/doc/concepts.html