• Navigation überspringen
  • Zur Navigation
  • Zum Seitenende
Organisationsmenü öffnen Organisationsmenü schließen
Lehrstuhl für Informatik 4 & 16
  • FAUZur zentralen FAU Website
  1. Friedrich-Alexander-Universität
  2. Technische Fakultät
  3. Department Informatik
  • English
  • Campo
  • UnivIS
  • Stellenangebote
  • Lageplan
  • Hilfe im Notfall
  1. Friedrich-Alexander-Universität
  2. Technische Fakultät
  3. Department Informatik

Lehrstuhl für Informatik 4 & 16

Menu Menu schließen
  • Lehrstuhl
    • Leitbild
    • Team
    • Kontakt und Anfahrt
    • 50-jähriges Jubiläum
    Portal Lehrstuhl
  • Forschung
    • Forschungsbereiche
      • Betriebssysteme
      • Echtzeitsysteme
      • Energiebewusste Systeme
      • Verteilte Systeme
    • Projekte
      • BFT2Chain
      • e.LARN
      • NEON
      • PAVE
      • PRIMaTE
      • REFIT
      • ResPECT
      • SURESOFT
      • TRR 89 C1: iRTSS
      • TRR 89 C5
      • Watwa
    • Projektkampagnen
      • DOSS
      • maRE
    • Forschungsgruppen
      • ergoo
    Portal Forschung
  • Publikationen
  • Lehre
    • Sommersemester 2023
      • Ausgewählte Kapitel der Systemsoftware
      • Betriebssystemtechnik
      • Projekt angewandte Systemsoftwaretechnik
      • Systemnahe Programmierung in C
      • Systemprogrammierung 1
      • Verteilte Systeme
    • Wintersemester 2023/24
      • Ausgewählte Kapitel der Systemsoftware
      • Betriebssysteme
      • Systemprogrammierung 2
      • Middleware – Cloud Computing
      • Virtuelle Maschinen
      • Web-basierte Systeme
    Portal Lehre
  • Examensarbeiten
  1. Startseite
  2. Extern

Extern

Bereichsnavigation: Lehre
  • Systemnahe Programmierung in C
    • Vorlesung
      • Übung
        • Folien
        • Aufgaben
        • SPiCboard
          • Bauanleitung
            • Programmieren im CIP
              • Programmieren von zu Hause
                • libspicboard-Doku
                  • SPiC-IDE
                    • SPiCsim
                      • FAQ
                        • Projekte
                        • Linux libc-Doku
                        • Prüfung
                          • Klausurergebnisse
                          • Evaluation
                            • Intern

                            Linux libc-Doku

                            Files | Functions
                            Memory

                            Files

                            file  stdlib.h
                             

                            Functions

                            void * malloc (size_t size)
                             Allocate memory. More...
                             
                            void free (void *ptr)
                             Free allocated memory. More...
                             

                            Detailed Description

                            With malloc() (memory allocation) a program can request memory from the operating system. The allocated memory is usable until it is free()'d again. It is important, that programs always check if a malloc() call was successful and free their memory after usage, otherwise a so-called memory leak exists.

                            // allocate memory
                            char *s = malloc(strlen("Hello World\n") + 1);
                            if (s == NULL) {
                            perror("malloc");
                            exit(EXIT_FAILURE);
                            }
                            // use allocated memory
                            strcpy(s, "Hello World\n");
                            printf("%s", s);
                            // free allocated memory
                            free(s);
                            printf
                            int printf(const char *format,...)
                            Print formatted data to stdout
                            perror
                            void perror(const char *s)
                            Print an error message.
                            malloc
                            void * malloc(size_t size)
                            Allocate memory.
                            free
                            void free(void *ptr)
                            Free allocated memory.
                            exit
                            void exit(int status)
                            Terminate process.
                            strcpy
                            char * strcpy(char *dest, const char *src)
                            Copy a string.
                            strlen
                            size_t strlen(const char *s)
                            Calculate the length of a string.

                            Function Documentation

                            void* malloc ( size_t  size)

                            The malloc() function allocates size bytes at the heap and returns a pointer to the allocated memory or NULL if an error has been occurred. Be aware, that the memory is not initialized after a successful call to malloc().

                            Parameters
                            sizenumber of bytes to be allocated
                            Return values
                            NULLon error, errno is set
                            !=NULLpointer to allocated memory
                            void free ( void *  ptr)

                            The free() function frees the memory pointed to by ptr, which must have been returned by a previous call to malloc(). Otherwise, or if free(ptr) has already been called before, undefined behavior occurs. If ptr is NULL, no operation is performed.

                            Parameters
                            ptrpointer to buffer
                            Friedrich-Alexander-Universität
                            Erlangen-Nürnberg

                            Schlossplatz 4
                            91054 Erlangen
                            • Impressum
                            • Datenschutz
                            • Barrierefreiheit
                            • Facebook
                            • RSS Feed
                            • Twitter
                            • Xing
                            Nach oben