Page 1 of 1

Storing 3D array in memory

Posted: Mon Aug 19, 2019 9:46 pm
by mantas
I'm trying to store a 3d array in memory

Code: Select all

int bigarray[5][12][50];

preferences.begin("my-app", false);
preferences.getBytes("calendar", bigarray, 3000);
preferences.end();
but it doesnt seem to be working any ideas?

Re: Storing 3D array in memory

Posted: Sat Aug 24, 2019 1:39 pm
by tommeyers
"It doesn't work" is not much to go on.

So if offer a method I have used to store, retrive and manage my own 2, 3, 4, 5 ... dimensional tables stored in memory or disk or ... .

A more experienced C programmer will maybe make it easier;

first:
int *myInt

then:
function int fetchMyInt(int x, int y, int z) {
fetch the data table
compute the location/byte offset (I think int is word size so each int is 4 bytes) using 4,x,y,z
compute table start + offset
return the integer value at table start + offset
}

Re: Storing 3D array in memory

Posted: Sat Aug 24, 2019 6:08 pm
by vonnieda
mantas wrote:
Mon Aug 19, 2019 9:46 pm
I'm trying to store a 3d array in memory

Code: Select all

int bigarray[5][12][50];

preferences.begin("my-app", false);
preferences.getBytes("calendar", bigarray, 3000);
preferences.end();
but it doesnt seem to be working any ideas?
I'm not sure what your various preferences calls do, but one thing that sticks out is that you declare an int array of size 5x12x50 and then call getBytes() using an argument of 3000. I imagine that call is reading 3000 bytes from somewhere and writing them to the array, and 5x12x50 is indeed 3000, but int is 4 bytes, not 1, so your array is actually 5x12x50x4 = 12000 bytes long, not 3000 bytes long.

Jason

Re: Storing 3D array in memory

Posted: Tue Aug 27, 2019 12:08 pm
by mantas
I changed my array to unsigned char to save space

but i still get error
[E][Preferences.cpp:457] getBytesLength(): nvs_get_blob len fail: calendar NOT_FOUND

thats the librrary im trying to use
https://github.com/espressif/arduino-es ... references