Login  Register

Re: binding a C functions that allocates two chunks of memory and returns an integer

Posted by ananyagupta on Nov 11, 2019; 12:30pm
URL: https://forum.jogamp.org/binding-a-C-functions-that-allocates-two-chunks-of-memory-and-returns-an-integer-tp3547863p4040141.html

I think this will help you just check:



realloc() “realloc” or “re-allocation” method is used to dynamically change the memory allocation of a previously allocated memory. In other words, if the memory previously allocated with the help of malloc or calloc is insufficient, realloc can be used to dynamically re-allocate memory.

This procedure is referred to as Dynamic Memory Allocation in C.

Therefore, C Dynamic Memory Allocation can be defined as a procedure in which the size of a data structure (like Array) is changed during the runtime.

C provides some functions to achieve these tasks. There are 4 library functions provided by C defined under <stdlib.h> header file to facilitate dynamic memory allocation in C programming. They are:

malloc()
calloc()
free()
realloc()
Let’s look at each of them in greater detail.

C malloc() method
“malloc” or “memory allocation” method in C is used to dynamically allocate a single large block of memory with the specified size. It returns a pointer of type void which can be cast into a pointer of any form.

Syntax:

ptr = (cast-type*) malloc(byte-size)
For Example:

ptr = (int*) malloc(100 * sizeof(int));

Since the size of int is 4 bytes, this statement will allocate 400 bytes of memory. And, the pointer ptr holds the address of the first byte in the allocated memory.

Here I share whatever I know because now i working as C language developer and for more :
https://www.cetpainfotech.com/technology/C-Language-Training