I am using raspistill
to acquire images with my PI. after some weeks my SD card is full and the whole thing dies so I need to install again.
so I added some code to see what's happening with my available memory.
Here is the code to assess my memory status.
//https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.2.0/com.ibm.zos.v2r2.bpxbd00/rstatv.htm
int r = statvfs(".", &buf);
if (r < 0) {
printf(" Error in statsvf");
memAvailable = 4; // exit
}
else {
memAvailable = (unsigned long)(buf.f_bavail * buf.f_bsize);
printf(" Memory available is %.0lu\n", memAvailable);
}
this is the result I'm getting:
- take a picture state 2
- Memory available is 6868992
- Turn: 325 working = 1 up = 1
- saving image at Pix/005/img014_2020-07-02_10-23-37.jpg
- Image saved take a picture state 2
- Memory available is 2777088
- Turn: 352 working = 1 up = 1
- saving image at Pix/005/img015_2020-07-02_10-23-46.jpg
- Image saved take a picture state 2
- Memory available is 4293648384
- Turn: 379 working = 1 up = 1
- saving image at Pix/005/img016_2020-07-02_10-23-55.jpg
- Image saved take a picture state 2
- Memory available is 4289556480
- Turn: 406 working= 1 up = 1
why is the available memory changing in the middle of the run mind you - I did not start or stop any program during this run, nor do I allocate a large size memory.
EDIT: My bad - it seems that 32GB is too long for an unsigned long. so i needed to assess only the f_bavail for my task. NOOB
You have an overflow when you do
buf.f_bavail * buf.f_bsize
because the computation is done using anunsigned long
which not enough for the free size of your partitionUse
unsigned long long
, for instance :You can also use
uint64_t
to be sure to have a unsigned integer on 64b.In my case :
and the result is compatible with the indication given by the command
df -H .
Note to write memory about a partition on a disk is not very clear and can be confused with the RAM