CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2005
    Posts
    37

    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!

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: dealing with very large arrays

    Quote 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.

    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Jan 2005
    Posts
    37

    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..?

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: dealing with very large arrays

    Quote 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?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: dealing with very large arrays

    [ Moved thread ]

  6. #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
  •  





Click Here to Expand Forum to Full Width

Featured