Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Question about memory allocation.

ngabordhngabordh Member Posts: 13
Hi.

How many memory can I allocate for my windows programs?
I `ve just started to deal with windows programming. In DOS
programming there were far, near pointers. So I used these things
to allocate the proper size of memory. In windows all pointers are
4 bytes long. So doest it meant that the amount of memory, I can

allocate is up to 4 Gbyte? A beginner`s question... :) Thanks.

Comments

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    [b][red]This message was edited by the AsmGuru62 at 2002-3-7 7:47:19[/red][/b][hr]
    : Hi.
    :
    : How many memory can I allocate for my windows programs?
    : I `ve just started to deal with windows programming. In DOS
    : programming there were far, near pointers. So I used these things
    : to allocate the proper size of memory. In windows all pointers are
    : 4 bytes long. So doest it meant that the amount of memory, I can
    :
    : allocate is up to 4 Gbyte? A beginner`s question... :) Thanks.
    :
    :
    Win32 task (application) has 4Gb to live in total. It consists from 2 parts:

    1. System memory -> 2Gb
    2. Private application memory -> 2Gb <- THIS IS THE AMOUNT FOR BOTH YOUR DATA AND CODE AND STACK.

    You can operate in this 2Gb vicinity - you can allocate mega-bytes and more... The only question is how much memory (RAM) your system has. More memory you allocate - more speed you lose because of memory page faults. Of course, the slowdown depends on how you allocate memory. Best way to allocate memory is by big chunks, not by small ones. That is why linked lists are slower than dynamically allocated arrays.

    The functions for memory allocations are:

    1. You can use malloc()/free() as in DOS - they now map into Win32 memory manager.

    2. You can use GlobalAlloc()/GlobalFree() - it is slower then others.

    3. You can use HeapCreate()/HeapAlloc()/HeapFree()... etc. These are the best and recommended to use in Win32 programs.

    4. You can go overboard and write your own heap memory manager which will overtake anything from ##1..3 in speed.

    Well, needless to say, I am as ASM guy implemented this last one.
    Also, there is VirtualAlloc() to get the huge chunks of memory.
    Read MSDN about memory management - cool reading I must say...

    Cheers!
    [blue]
    P.S. In MFC just use new/delete they also mapped to the functions I was talking about.[/blue]


  • ngabordhngabordh Member Posts: 13
    : [b][red]This message was edited by the AsmGuru62 at 2002-3-7 7:47:19[/red][/b][hr]
    : : Hi.
    : :
    : : How many memory can I allocate for my windows programs?
    : : I `ve just started to deal with windows programming. In DOS
    : : programming there were far, near pointers. So I used these things
    : : to allocate the proper size of memory. In windows all pointers are
    : : 4 bytes long. So doest it meant that the amount of memory, I can
    : :
    : : allocate is up to 4 Gbyte? A beginner`s question... :) Thanks.
    : :
    : :
    : Win32 task (application) has 4Gb to live in total. It consists from 2 parts:
    :
    : 1. System memory -> 2Gb
    : 2. Private application memory -> 2Gb <- THIS IS THE AMOUNT FOR BOTH YOUR DATA AND CODE AND STACK.
    :
    : You can operate in this 2Gb vicinity - you can allocate mega-bytes and more... The only question is how much memory (RAM) your system has. More memory you allocate - more speed you lose because of memory page faults. Of course, the slowdown depends on how you allocate memory. Best way to allocate memory is by big chunks, not by small ones. That is why linked lists are slower than dynamically allocated arrays.
    :
    : The functions for memory allocations are:
    :
    : 1. You can use malloc()/free() as in DOS - they now map into Win32 memory manager.
    :
    : 2. You can use GlobalAlloc()/GlobalFree() - it is slower then others.
    :
    : 3. You can use HeapCreate()/HeapAlloc()/HeapFree()... etc. These are the best and recommended to use in Win32 programs.
    :
    : 4. You can go overboard and write your own heap memory manager which will overtake anything from ##1..3 in speed.
    :
    : Well, needless to say, I am as ASM guy implemented this last one.
    : Also, there is VirtualAlloc() to get the huge chunks of memory.
    : Read MSDN about memory management - cool reading I must say...
    :
    : Cheers!
    : [blue]
    : P.S. In MFC just use new/delete they also mapped to the functions I was talking about.[/blue]
    :
    :
    :

    Ok. Thank you. This little thing helped me a lot!

Sign In or Register to comment.