Thread: memory question

  1. #1
    Registered User madsmile's Avatar
    Join Date
    Feb 2002
    Posts
    26

    memory question

    I have a little question... with this like what do i do...


    char *k = new char[30] ;

    i know this makes a pointer "K" to a structure of 30 chars.. but this works on the heap... i want to do it on the ram memory... i have read something about farmalloc and farcalloc... but that's c, how do i do that on c++

    the problem is that i need to alloc about 5 MB without fill the heap.. i just want to do it on the ram (extended memory...)
    MADSmile
    ICQ #3653692
    (i'm running Borlad C++ Ver 3.1 under MSDOS)

  2. #2
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    What platform are you compiling to? If you are doing a Console program, there is no way you can allocate 5 MB to the stack. You would have to do it to the heap. And why dont you wanna do it to the heap? Heap, stack...whatever...its all RAM...

    If you are doing a Windows program you might have the ability to allocate 5 MB to the stack...but still...i dont think you would want to...definitely do it to the heap...
    My Website

    "Circular logic is good because it is."

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    52
    That's no little question You're asking.

    MSDN states that the heap is a portion of memory reserved for an application to use for the temporary storage of data structures whose existence or size cannot be determined until the application is running. The application can request free memory from the heap to hold such elements, use it as necessary, and later free the memory.

    In short, the HEAP is that portion of RAM allocated to your program by the operating system.

    You can resize the HEAP, see your compiler docs. There is a limit which is OS dependent.

    >>i have read something about farmalloc and farcalloc... but
    >>that's c, how do i do that on c++

    I think what you are refering to is known as near and far pointers. In 16 bit and earlier systems the heap was divided into a near heap and a far heap. All memory models had access to the near heap. You needed a far pointer to access the far heap. With the introduction of 32 bit systems, near and far pointers are unnecessary.

    Once again you will need to refer to your compilers docs to learn about them for your system and compiler.

  4. #4
    Registered User madsmile's Avatar
    Join Date
    Feb 2002
    Posts
    26
    yeah i have read the docs... is on borland c++ v3.1

    the problem is that i need to alloc about 5 mb... i know this can be posible, but the heap on DOS is just 640Kb so i run out of memory in about 0.03 seconds i can alloc memory on the ram with farmalloc and farcalloc... but it allways fill the heap first... i just need it to alloc on the ram...

    Code:
    ----------------
    heap 64k
    ----------------
    RAM 128 MB
    (I NEED TO ALLOC just here...)
    ----------------

    that's my problem....
    MADSmile
    ICQ #3653692
    (i'm running Borlad C++ Ver 3.1 under MSDOS)

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    52
    Assuming you're using a 16 bit system, you must learn to use near, far, and huge pointers. I don't know what Borland has, but MS uses keywords: _near, _far, and _huge. The last compiler I used that supported such pointers was MS Quick C with MS-DOS 5.0.

    I don't know Borland compilers.

    Good luck,

  6. #6
    Registered User GreenCherry's Avatar
    Join Date
    Mar 2002
    Posts
    65
    Mwahahaha!

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    If it was me, I would do this:

    const long mem_size = 10000000;

    char *a;
    a = new char[mem_size];
    .
    .
    .
    delete []a;

  8. #8
    Unregistered
    Guest

    You need FXVMM or something similar

    You need FXVMM or something similar to write
    to Extended memory.

    You can search for the above freebie lib.
    It isn't very well documented though but it seems
    to work. It also automatically includes virtual
    memory etc. Uses quite a bit of assembler and
    the source code is included.

    Last version is about 2.01

    Search for FXVMM201.ZIP

    Alternatively you coule purchase a XMS dos extender library for the compiler.

    Regards

    Mark

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > is on borland c++ v3.1
    Are you actually running this in DOS, or just inside some DOS window running on Win95/Win98/NT/2K etc?

    If it's the latter, then get a decent compiler - one which isn't stuck in the 16 bit stone age

    DJGPP has no probs allocating 5MB

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. heap vs stack memory question
    By donglee in forum C++ Programming
    Replies: 4
    Last Post: 01-23-2009, 04:34 PM
  2. Pointer memory question
    By Edo in forum C++ Programming
    Replies: 5
    Last Post: 01-21-2009, 03:36 AM
  3. Memory question
    By John_L in forum Tech Board
    Replies: 8
    Last Post: 06-02-2008, 10:06 PM
  4. Another Dynamic Memory Question
    By SirCrono6 in forum C++ Programming
    Replies: 6
    Last Post: 03-02-2005, 12:10 PM
  5. Is it necessary to write a specific memory manager ?
    By Morglum in forum Game Programming
    Replies: 18
    Last Post: 07-01-2002, 01:41 PM