1

Is there a way to change where malloc allocate memory space?

For an example, let's say I want malloc to allocate memory within 0x100000 and 0x500000. How can I do this or is there a way for this without changing the malloc implementation?

Sanka Darshana
  • 1,391
  • 1
  • 23
  • 41

2 Answers2

0

You probably cannot change the behavior of the standard malloc call (aside from runtime substitutions such as via LD_PRELOAD), but for some platforms can write your own (separate) memory allocator using specific addresses with the mmap function call.

Community
  • 1
  • 1
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
0

Using malloc allocates memory on the heap.If your question is related to an embedded software, you can often change the heap start address,size and other parameters in the startup file or linker configuration file.

user3415290
  • 45
  • 1
  • 6