top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Memory allocation without malloc function?

+4 votes
965 views

Is there any alternate function is available?

posted Oct 3, 2013 by Giri Prasad

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

5 Answers

+1 vote

My solution would be allocating a global byte-array, that would be used instead of the heap (non melloc allocation) and you are free to use it as you want but you have to do memory management yourself:

char heap[MAX_ALLOWED_MEM];

/*
   The following function uses 'heap' as raw memory!
   void* like_malloc(size_t bytes);
   ...
*/

Check if you are ok with calloc, but internally both are same more or less.

answer Oct 3, 2013 by Salil Agrawal
Hi Salil,
I dont want to use any Heap function like malloc,calloc..so is thr any alternate way to allocate memory?
Thats what I said u can create a global memory pool and allocate from that pool and free into that pool. This is the only option as far as I know.
good one.. but it will be difficult as you have to do forward and reverse to use and free memory.
+1 vote

Use calloc(int num,sizeof(datatype)) function.
example
int *p = calloc(1 , sizeof(int) * 4);
it allocate a single row block of 8 byte.

first argument is used for no. of row and 2nd for size of block.

answer Oct 3, 2013 by Dheerendra Dwivedi
Hi
I dont want to use any Heap function like malloc,calloc.
0 votes

Use void *calloc(size_t num, size_t size) function.

answer Oct 3, 2013 by anonymous
0 votes

Allocate bulk of memory statically and create your own function to manipulate that.

answer Mar 20, 2014 by sivanraj
0 votes

use the calloc function;
syntex- int *arr;
arr=(int *)calloc(n,sizeof(int));

answer Dec 20, 2015 by Shishir Chaudhary
...