Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ Language Reference - sbrk http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
   sbrk

   Usage
   #include <stdlib.h>
   void *sbrk(unsigned int count);

   Description
   sbrk  attempts  to  enlarge the data segment by the  number  of  bytes
   specified  in  count.  A pointer to the added memory  is  returned  on
   success, else -1 if error.

   For T, S and M models if the variable _okbigbuf was not defined,  then
   all  available memory up to 64k is allocated during  program  start-up
   and  sbrk will always fail (return a -1). If in the program  _okbigbuf
   is  defined and initialized to 0, then only the memory required  by  a
   program is allocated to the heap and sbrk will be usable.

   For C and L models, if sbrk() cannot extend the data segment, it  will
   try to allocate a new one.

   sbrk()  is  an integral part of calloc(),   malloc(),  and  realloc().
   Applications should avoid using it.

   Example
   #include <stdlib.h>
   #include <stdio.h>
   void *sbrk(int);
   main()
   {
   unsigned int count = 100;
   char *ptr;
        ptr = sbrk(count);
        if(ptr == (char *)-1)
        {
             perror("No available space for sbrk\n");
             return;
        }
        strcpy(ptr,"String of data:");
        strcat(ptr," another string added\n");
        fputs(ptr,stdout);
   }

   Return Value
   sbrk  returns  a  -1 if there was not enough  memory  to  satisfy  the
   request and errno is set. Otherwise, a pointer to the memory block  is
   returned.


See Also: calloc free malloc realloc

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