Yes C++, sorry for not being clear.
First of all, while reading the code, I kinda understood why this is not all that simple, because the program doesn't know how much memory you'll be needing and therefor allocates a batch for you that you requested at THAT moment, but if you would want to keep on allocating one extra int every loop (stacking it up), the program would eventually come to a block, where the memory's already reserved. Am I anywhere close to being right?
So yes, thank you for the vectors, but just to be more clear, I'll write a simple idea (code):
1 2 3 4 5 6 7 8 9 10
|
int *ptr = new int;
for (i = 0; i < bignumber; i++)
{
num = (rand() % 10) + 1;
if (bignumber % num == 0)
*(ptr+1) = num;
}
|
So in this case we would need to increase the mem alloc to ptr every time we fell in the if statement, but we don't know how big the size we would need, so I would like to allocate one more int to ptr when needed, like:
_ <- size of memory pointed to by ptr:
0x941F <- just an example address location pointed to by ptr.
0x941F. _,
0x941F. _ _,
0x941F. _ _ _,
0x941F. _ _ _ _ ,
0x941F. _ _ _ _ _,
I think you get the point.
Now as I said in the beginning, after some thought I don't think this is something simple and everyday as I had hoped it would be.
Thanks again.