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++ 3.0r4 - <b>sbrk</b> 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..

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

Example 

   #include <stdio.h>
   #include <stdlib.h>
   #include <string.h>
   #include <stdlib.h>

   extern _okbigbuf = 0;
   void *sbrk(int);

   int main()
   {
       unsigned int count = 100;
       char *ptr;
       ptr = sbrk(count);
       if(ptr == (char *)-1L)
           {

               perror("No available space for sbrk\n");
               return EXIT_FAILURE;
           }
       strcpy(ptr,"String of data:");
       strcat(ptr," another string added\n");
       fputs(ptr,stdout);
       return EXIT_SUCCESS;
   }

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



See Also: calloc free malloc realloc

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