CArray and memory allocation
-
I wonder if there's a way of making Windows not reallocate the memory for CArray objects without using CArray::SetSize(int) function? I mean I want to create a dynamic array of relatively large objects and I need pointers to the elements. When I add a new element with CArray::Add function, the operating system reallocates the memory and my pointers to the previous elements become invalid. Is there any way of 'fixing' the addresses of the elements?
-
I wonder if there's a way of making Windows not reallocate the memory for CArray objects without using CArray::SetSize(int) function? I mean I want to create a dynamic array of relatively large objects and I need pointers to the elements. When I add a new element with CArray::Add function, the operating system reallocates the memory and my pointers to the previous elements become invalid. Is there any way of 'fixing' the addresses of the elements?
Space Ace wrote: When I add a new element with CArray::Add function, the operating system reallocates the memory and my pointers to the previous elements become invalid. Not really. I suspect there are problems in your code. Can you post a sample? /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com
-
I wonder if there's a way of making Windows not reallocate the memory for CArray objects without using CArray::SetSize(int) function? I mean I want to create a dynamic array of relatively large objects and I need pointers to the elements. When I add a new element with CArray::Add function, the operating system reallocates the memory and my pointers to the previous elements become invalid. Is there any way of 'fixing' the addresses of the elements?
If it's anything like vector you should be able to pass an initial size into the constructor, then it won't reallocate until you go over that size. That naturally removes one of the main advantages of a dynamic array. By the way, CArray is absolute trash, you should ditch it and use vector instead. Christian We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum ) Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
-
I wonder if there's a way of making Windows not reallocate the memory for CArray objects without using CArray::SetSize(int) function? I mean I want to create a dynamic array of relatively large objects and I need pointers to the elements. When I add a new element with CArray::Add function, the operating system reallocates the memory and my pointers to the previous elements become invalid. Is there any way of 'fixing' the addresses of the elements?
Hello, the codegurus around the world.;) Generally speaking, we can define Find function to find CArray index. So, without the pointer of CArray, we can find any index with some key value. This means if we derived some class from CObject, we can insert this class in CArray template. (Or, I misunderstand something? X| ) Please, don't send me your email about your questions directly. Have a nice day! Sonork - 100.10571:vcdeveloper ;)
-Masaaki Onishi-
-
I wonder if there's a way of making Windows not reallocate the memory for CArray objects without using CArray::SetSize(int) function? I mean I want to create a dynamic array of relatively large objects and I need pointers to the elements. When I add a new element with CArray::Add function, the operating system reallocates the memory and my pointers to the previous elements become invalid. Is there any way of 'fixing' the addresses of the elements?
Store the index instead of the pointer. You can always get the pointer back. Joel Lucsy (jjlucsy@ameritech.net)