• Navigation überspringen
  • Zur Navigation
  • Zum Seitenende
Organisationsmenü öffnen Organisationsmenü schließen
Friedrich-Alexander-Universität Lehrstuhl für Informatik 4 (Systemsoftware)
  • FAUZur zentralen FAU Website
  1. Friedrich-Alexander-Universität
  2. Technische Fakultät
  3. Department Informatik
Suche öffnen
  • English
  • Campo
  • StudOn
  • FAUdir
  • Stellenangebote
  • Lageplan
  • Hilfe im Notfall
  1. Friedrich-Alexander-Universität
  2. Technische Fakultät
  3. Department Informatik
Friedrich-Alexander-Universität Lehrstuhl für Informatik 4 (Systemsoftware)
Menu Menu schließen
  • Lehrstuhl
    • Team
    • Aktuelles
    • Kontakt und Anfahrt
    • Leitbild
    • 50-jähriges Jubiläum
    Portal Lehrstuhl
  • Forschung
    • Forschungsbereiche
      • Betriebssysteme
      • Confidential Computing
      • Eingebettete Systemsoftware
      • Verteilte Systeme
    • Projekte
      • AIMBOS
      • BALu
      • BFT2Chain
      • DOSS
      • Mirador
      • NEON
      • PAVE
      • ResPECT
      • Watwa
    • Projektkampagnen
      • maRE
    • Seminar
      • Systemsoftware
    Portal Forschung
  • Publikationen
  • Lehre
    • Sommersemester 2025
      • Applied Software Architecture
      • Ausgewählte Kapitel der Systemsoftware
      • Betriebssystemtechnik
      • Projekt angewandte Systemsoftwaretechnik
      • System-Level Programming
      • Systemnahe Programmierung in C
      • Systemprogrammierung 1
      • Verteilte Systeme
    • Wintersemester 2024/25
      • Betriebssysteme
      • Middleware – Cloud Computing
      • Systemprogrammierung 2
      • Verlässliche Echtzeitsysteme
      • Virtuelle Maschinen
      • Web-basierte Systeme
    Portal Lehre
  • Examensarbeiten
  1. Startseite
  2. Extern

Extern

Bereichsnavigation: Lehre
  • Systemnahe Programmierung in C (für Wiederholer)
    • SPiCboard
      • Prüfung
        • Evaluation
          • Linux libc-Doku
            • 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
            • Xing
            Nach oben