Top "Dynamic-memory-allocation" questions

Dynamic memory allocation, usually in the context of languages without garbage collection or mandatory or automatic reference counting, refers to the process or asking the operating system for a variable sized block of memory.

Proper usage of realloc()

From man realloc:The realloc() function returns a pointer to the newly allocated memory, which is suitably aligned for any …

c memory-leaks dynamic-memory-allocation realloc calloc
realloc() invalid old size

I am doing an exercise for fun from KandR C programming book. The program is for finding the longest line …

c dynamic-memory-allocation realloc
How to declare a variable size 2D array in C?

I have a problem with a project. I have to make a variable size 2D array for storing some prediction …

c arrays multidimensional-array dynamic-memory-allocation
alternative to strdup

I'm writing a C++ class for a book that contains a name: class Book { private: char* nm; .......... ............ .......... ........... }; I am not …

c++ string dynamic-memory-allocation strdup
Memory allocation for array on Stack or Heap (C)

Consider the following C code: #include <stdio.h> #include <stdlib.h> int main() { int arrSize; scanf("%…

c dynamic-memory-allocation static-memory-allocation
Read numbers from file into a dynamically allocated array

I need a function that reads grades (integers) from from file and returns a dynamically allocated array in which they …

c arrays file-io dynamic-memory-allocation formatted-input
Simple C implementation to track memory malloc/free?

programming language: C platform: ARM Compiler: ADS 1.2 I need to keep track of simple melloc/free calls in my project. …

c dynamic-memory-allocation
Overhead to using std::vector?

I know that manual dynamic memory allocation is a bad idea in general, but is it sometimes a better solution …

c++ stdvector dynamic-memory-allocation
How much memory should you be able to allocate?

Background: I am writing a C++ program working with large amounts of geodata, and wish to load large chunks to …

c++ new-operator dynamic-memory-allocation
C++ Allocate dynamic array inside a function

so I need to allocate an array of int inside a function. The array is declared before calling the function (…

c++ vector pass-by-reference dynamic-memory-allocation function-definition