how to double an array size?

This is a discussion on how to double an array size? within the C++ Programming forums, part of the General Programming Boards category; I was wondering how do i increase an array size.
Example:
string *array;
array = new string[10];
and I want ...

You could also use the placement new operator and the C memory management functions, but vectors are a wise choice. I think you'd be amazed at how much info you can find about these types of questions by simply googling (and I say that not to be condescending so much as for your benefit of not having to read snide remarks about what you are asking not to mention the length of time that sometimes lapses between asking and a response).

You could also use the placement new operator and the C memory management functions, but vectors are a wise choice. I think you'd be amazed at how much info you can find about these types of questions by simply googling (and I say that not to be condescending so much as for your benefit of not having to read snide remarks about what you are asking not to mention the length of time that sometimes lapses between asking and a response).

Whilst that is a clever solution, I'm 99% sure that's not really the solution the original poster was looking for.

In that case I will allow the original poster an opportunity to ponder the one and only solution left that the instructor is looking for them to be implementing. Though if its an assignment, surely the placement new operator trick would impress the teacher.

Given zero credit due to free thinking and denoting one kilobyte in the most confusing notation possible.

Actually, when I saw your cute snippet, the first thing that came to mind was "not general enough", since the capacity is fixed, at least from what I understand. I also did not recall an example where the buffer was not a dynamic array... and this guy claims that Placement-New Requires Heap-Allocated Buffers, but personally I cannot parse the relevant text of the C++ Standard to determine either way.

Well I mostly trying to demonstrate an unusual method more than a realistic one. The *alloc() solution I pitched earlier is really more what the placement operator was designed for (in concept not in practice... so I refuse to reply to anyone who says "they were created for custom memory manager and/or separate heap allocation"). After writing that I realized how infrequently any of us actually use octal number strings.

Well I mostly trying to demonstrate an unusual method more than a realistic one.

Fair enough. Still, do you agree with Danny Kalev, or is there some flaw in his reasoning?

The *alloc() solution I pitched earlier is really more what the placement operator was designed for (in concept not in practice... so I refuse to reply to anyone who says "they were created for custom memory manager and/or separate heap allocation").

Allocators and the like are still deep magic to me, but that is what I had in mind when I implied that there was a non-naive implementation to what dotz02x was starting to get at. My understanding is drawn from Allocating Arrays Using Placement new (also by Kalev, does that guy have a fetish with placement new or what?), which I once linked to someone who asked how std::vector might implement the constructor that takes an iterator pair or the constructor that takes a size and initial value.

After writing that I realized how infrequently any of us actually use octal number strings.

Or rather, numbers in octal representation. But yeah, I parse decimal and hexadecimal representations far more easily.

Actually, when I saw your cute snippet, the first thing that came to mind was "not general enough", since the capacity is fixed, at least from what I understand. I also did not recall an example where the buffer was not a dynamic array... and this guy claims that Placement-New Requires Heap-Allocated Buffers, but personally I cannot parse the relevant text of the C++ Standard to determine either way.

Strictly speaking, I think that link is correct, but the requirement isn't that it needs to be heap allocated as such - it just needs to be aligned correctly - for a char array, that would no big deal, and as long as your "placement" array is based on an element that is of equal or larger size than the largest single element of whatever you are trying to "place" there, then it will be fine (so for example, placing a short on top of an int array should be fine, but an int on top of a short array won't necessarily). If you use a char array, and "oversize" by 1 alignment size and manually align it, it will also work just fine.