This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Checking for memory usage on runtime

Hey everyone,

I'm having problems with my app's ram usage as you can see from my previous questions.

I've tried this little piece of code:

void memcheck(void){
	// perform free memory check
	int blockSize = 16;
	int i = 1;
	debug("Checking memory with blocksize %d char ...\n", blockSize);
	while (true) {
		char *p = (char *) malloc(i * blockSize);
		if (p == NULL){
			break;
		}
		free(p);
		++i;
	}
	debug("Ok for %d char\n", (i - 1) * blockSize);
}

That I found here to test for free memory.

I get this output:

Test for free memory Checking memory

with blocksize 16 char ...

Ok for 4752 char

And then my application just breaks. I've checked and it seems to me that the memory that was mallock'd should be freed, so I don't understand where this is wrong. What's more interesting is that this behavior is eerily similar to the behavior I get when I try running the lwip stack alongside my app (see here and here).

Can you guys help me understand what is going on here?

Parents
  • Just to be clear here, you're testing the size of the heap space allocated during link time and not exactly the RAM usage of your app. Take a look in the file arm_startup_nrf51.s for your project and the label Heap_Size near the top. It is either set with an EQU statement or assigned a value passed in from the project settings of the build environment.

    I also agree with Aryan that it doesn't appear your app is "breaking" - you should explain what that means in greater detail.

    Dan

Reply
  • Just to be clear here, you're testing the size of the heap space allocated during link time and not exactly the RAM usage of your app. Take a look in the file arm_startup_nrf51.s for your project and the label Heap_Size near the top. It is either set with an EQU statement or assigned a value passed in from the project settings of the build environment.

    I also agree with Aryan that it doesn't appear your app is "breaking" - you should explain what that means in greater detail.

    Dan

Children
Related