2d Arrays, Accessing and External LUT

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Docara
Posts: 315
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 61 times
Contact:

2d Arrays, Accessing and External LUT

Post by Docara »

Hi

I'm trying to convert a C program into FC7
I need at least one 8 byte Array ( num[0] or more correctly num[0][8] ) but ultimately an unknown number ( num [x][8] ) but x ultimately could be close to 100+

So can FC implement and actively use this type of scheme/structure (English terms not programming terms).

I would like to access these 8bytes as one for example car = num[7][8], dog=num[206][8] - I was thinking of a LUP and pointers to external memory but I notice FC only supports 32bits not 64bits. Again is FC able to do this and if so, how could FC implement it?

Lastly, as a general question, how could I auto populate FC's LUT component when it seems to require manual entering on numbers.

Thanks

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: 2d Arrays, Accessing and External LUT

Post by mnf »

You can use 2d (or more) arrays in FC - define then as x[2][3] as per C.

You could use a LUT - and simulate the 2d access - so x[a] [bb] = LUT.GetElement(a * size of element) + bb. I would however question whether this is a good idea for a very large data set - how is it going to be stored / load (SD card, memory chip etc)

One thing to watch is that this can be wasteful - for example storing strings - each element must be large enough to hold the largest string possible - but bytes are wasted on smaller strings.

What hardware is this to run on - 32 bit still allows quite a large table! For example - would if the data is stored on SD card a subset of the table could be loaded to memory at a time. If stored in an EEPROM - then it could just be accessed directly.

So. Give us some more detail on how the data is to be stored - loaded etc - and how big the expected table will be. How fast does access need to be - it might be possible to use a linked list for example - but access will be slower. Or for slightly more complication a tree. Alternatively - a database could be the way to go (though accessing through FC will be hard)

Martin

Docara
Posts: 315
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 61 times
Contact:

Re: 2d Arrays, Accessing and External LUT

Post by Docara »

Hi Martin,

I am trying to implement a hardware search routine and storage for One Wire device which have addresses that are 32bits / 8 Bytes long. and the results initially will be stored EEPROM (somewhere) - probably an external I2C EEPROM.

The MCU doesn't matter - its' governed by other criteria anyway, however I was looking at the Nucleo Cortex M3+ (I think) based stuff for V. low power

Just doing a proof of concept at the mo, done portions of it in ASM, jumped over to Atmel Studio to make it stand alone C. Now seeing which is the favourable route with FC - a C block or fully implement the code with in FC. AND whether or not I can program it.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: 2d Arrays, Accessing and External LUT

Post by kersing »

Last time I checked 32 bits were 4 bytes, not 8 bytes. (4 * 8 = 32)
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: 2d Arrays, Accessing and External LUT

Post by mnf »

Should be reasonably easy to do a search - how many devices will be in the table? You can either loop through them, checking for a match or use a 'hash' function (for example add together the bytes of the address and use this (mod number of 'buckets')* to index the first item of a linked list) or use a tree structure. ( What you can't/shouldn't do is use the 32 bit number as an index - as this will require too much storage - I guess the table will be fairly sparsely populated with data)

* Knuth's 'art of programming' is a good read.

Trees and lists can be implemented in FC - even though it doesn't really support the concept of a pointer - just use an int (16 or 32 bit as required) and use this an index.....

I wrote a short Python program to copy data from pc to i2c memory (I used 24lc256 and Arduino but should be portable) - if it would be helpful...

Martin

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: 2d Arrays, Accessing and External LUT

Post by mnf »

Should be reasonably easy to do a search - how many devices will be in the table? You can either loop through them, checking for a match or use a 'hash' function (for example add together the bytes of the address and use this (mod number of 'buckets')* to index the first item of a linked list) or use a tree structure. ( What you can't/shouldn't do is use the 32 bit number as an index - as this will require too much storage - I guess the table will be fairly sparsely populated with data)

* Knuth's 'art of programming' is a good read

Trees and lists can be implemented in FC - even though it doesn't really support the concept of a pointer - just use an int (16 or 32 bit as required) and use this an index.....

I wrote a short Python program to copy data from pc to i2c memory (I used 24lc256 and Arduino but should be portable) - if it would be helpful...

Martin

Post Reply