Click to See Complete Forum and Search --> : dealing with very large arrays


psasidisrcum
February 28th, 2005, 02:26 PM
Hi all,

I'm creating a simple Notepad-like application that allows basic editing of text. I'm assuming that the characters would have to be stored in an array, either a 2D wchar_t array, or a 1D wstring array (would one be better than the other..?)

How does one deal with the problem of allocating enough memory for the array?
Since it's not possible to know, in advance, how many lines of characters the array will have to store, do I have to dynamically allocate a new array each time the enter key is pressed, copy the contents of the old array to the new array, and delete the old array? This strikes me as a somewhat inefficient method.

More importantly though, would I soon run out of memory using such a method? ie. would this method support thousands of lines of characters? I don't know much about what VC++ will let me get away with, as far as array sizes go.

Someone must've had some experience with this. Thanks in advance for any help!

cilu
February 28th, 2005, 04:12 PM
I'm creating a simple Notepad-like application that allows basic editing of text. I'm assuming that the characters would have to be stored in an array, either a 2D wchar_t array, or a 1D wstring array (would one be better than the other..?)
Well, you can basically do that with justa few mouse clicks and not like of code written by you whatsoever.

Create a MFC Application, select SDI Application, and make sure that your view is CEditView. Finish, compile and run. Have fun with it.

:wave:

psasidisrcum
February 28th, 2005, 04:15 PM
Thanks, but I unfortunately don't know the MFC and don't plan on learning them. I'm using the Win32 API to build it from scratch. :) Anyone else on my original question..?

cilu
February 28th, 2005, 04:22 PM
I'm using the Win32 API to build it from scratch.
Sorry for asking, but is there a particular reason for this? Or you just like to reinvent the wheel (as we all like to do ;) )? Are you planing on building some smarter notepad?

Andreas Masur
February 28th, 2005, 04:30 PM
[ Moved thread ]

SirNotApearingOnThisForum
March 1st, 2005, 03:07 AM
What I would do is to have a set block size and start by a simple HeapAlloc() or GlobalAlloc(), then if the user's information exceeds the size of that block, just reallocate the memory with a function such as GlobalReAlloc() or HeapReAlloc(). This way there would only be the need for reallocation rarely.