Please critique my String Class
Posted on 2006-05-29
Here's my idea:
- Data is held internally in a char* initialized to an array of 128 chars.
- Each instance has a BufferLength unsigned int
- Data is assigned with an overloaded = operator. (The argument is a const char*)
- If the length of the argument is longer than our buffer, bit shift the buffersize to the left by 1 (double it in size)
Static Methods & Variables
- Whenever a delete is performed, add the buffer-being-deleted to one of the static queues
- Static queues are of type "A structure" from above and come in these flavors according to buffer size:
- 128-size queue
- 256-size queue
- 512-size queue
- .... so on up to a point
When a new buffer is created, the appropriate queue is checked to see if a block of memory is available (has previous been freed up)
- If a buffer is available, dequeue it and it becomes the memory-block for the current string instance
- If a buffer is not available, simply allocate a new one
I'm going to do some stress testing on this design, but at this point in time it sounds pretty good to me.
Can anybody spot some major flaws in this design? Or perhaps i didn't explain it clearly?