Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>_memmax() gets size of largest memory block</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 _memmax()               Gets size of largest memory block

 #include   <malloc.h>

  size_t _memmax(void);

    _memmax() returns the size (in bytes) of the largest contiguous block
    of memory that can be allocated from the near heap. Calling
    _nmalloc(_memmax()) will succeed as long as _memmax() returns a
    nonzero value.

    Returns:    If successful _memmax() returns the largest block size.
                If unsuccessful it returns 0, indicating no more memory
                can be allocated from the near heap.

   Portability:     MS-DOS only

 -------------------------------- Example ---------------------------------

 This program attempts to allocate _memmax bytes from the near heap.

           #include <stdio.h>
           #include <malloc.h>

           main()
           {
              size_t max_block = _memmax();
              char near *p;

              /* Allocation attempt #1 - succeeds */
              if (max_block)
                 {
                 if ((p = _nmalloc(max_block)) != NULL)
                    printf("Memory block allocated\n");
                 else
                    printf("Memory block allocation failed\n");
                 }
              else
                 printf("Near heap is full\n");

              /* Allocation attempt #2 - fails */
              max_block = _memmax();

              if (max_block)
                 {
                 if ((p = _nmalloc(max_block)) != NULL)
                    printf("Memory block allocated\n");
                 else
                    printf("Memory block allocation failed\n");
                 }
              else
                 printf("Near heap is full\n");
           }


See Also: malloc() _msize()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson