|
-
February 28th, 2005, 03:26 PM
#1
dealing with very large arrays
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!
-
February 28th, 2005, 05:12 PM
#2
Re: dealing with very large arrays
 Originally Posted by psasidisrcum
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.
-
February 28th, 2005, 05:15 PM
#3
Re: dealing with very large arrays
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..?
-
February 28th, 2005, 05:22 PM
#4
Re: dealing with very large arrays
 Originally Posted by psasidisrcum
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?
-
February 28th, 2005, 05:30 PM
#5
Re: dealing with very large arrays
-
March 1st, 2005, 04:07 AM
#6
Re: dealing with very large arrays
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|