I want to lock the memory to physical RAM in C with mlock and munlock, but I'm unsure about the correct usage.
Allow me to explain in a step by step scenario:
Let's assume that I dynamically allocate a pointer using calloc:
char * data = (char *)calloc(12, sizeof(char*));
Should I do mlock right after that?
Let's also assume that I later attempt to resize the memory block with realloc:
(char *)realloc(data, 100 * sizeof(char*));
Note the above increase amount ( 100 ) is random and sometimes i will decrease the memory block.
Should I first do munlock and then mlock again to address the changes made?
Also when I want to free the pointer data later, should I munlock first?
I hope someone can please explain the correct steps to me so I can understand better.