Storing 3D array in memory

mantas
Posts: 2
Joined: Mon Aug 19, 2019 9:43 pm

Storing 3D array in memory

Postby mantas » 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?

tommeyers
Posts: 184
Joined: Tue Apr 17, 2018 1:51 pm
Location: Santiago, Dominican Republic

Re: Storing 3D array in memory

Postby tommeyers » Sat Aug 24, 2019 1:39 pm

"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
}
IT Professional, Maker
Santiago, Dominican Republic

vonnieda
Posts: 145
Joined: Tue Nov 07, 2017 3:42 pm

Re: Storing 3D array in memory

Postby vonnieda » Sat Aug 24, 2019 6:08 pm

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

mantas
Posts: 2
Joined: Mon Aug 19, 2019 9:43 pm

Re: Storing 3D array in memory

Postby mantas » Tue Aug 27, 2019 12:08 pm

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

Who is online

Users browsing this forum: No registered users and 67 guests