SlideServe
Menu
Préférences
© SlideServe · v2026

Chapter 14 Memory API

varian avatar
4 diapositives · 189 Views · Aug 02, 2014

Chapter 14 Memory API. Chien -Chung Shen CIS, UD cshen@cis.udel.edu. Types of M emory. Stack (or automatic) memory – managed implicitly by compiler for programmer void func () { int x; // declares an integer on the stack ... } Heap memory – explicitly managed by programmer

Chapter 14 Memory API - slide 1
01 / 4Chapter 14 Memory API
1 / 17

Télécharger la présentation

Chapter 14 Memory API
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Chapter 14Memory API Chien-Chung Shen CIS, UD cshen@cis.udel.edu

  2. Types of Memory • Stack (or automatic) memory – managed implicitly by compiler for programmer void func() { intx; // declares an integer on the stack ... } • Heap memory – explicitly managed by programmer void func() { int*x = (int *) malloc(sizeof(int)); ... }

  3. Size of Memory Allocation int *x = malloc(10 * sizeof(int)); printf("%d\n", sizeof(x)); inty[10]; printf("%d\n", sizeof(y)); • there is enough static information for compiler to know that 40 bytes have been allocated • sizeof()is a compile-time operator

  4. Memory Bugs • Forget to allocate memory char *src= "hello”; char *dst; // oops! unallocated strcpy(dst, src); // segfault and die • Not allocate enough memory char *src= "hello"; char *dst= (char *) malloc(strlen(src)); // too small! strcpy(dst, src); // work properly, but buffer overflow • Forget to initialize allocated memory • Forget to free memory – memory leak