This seems such a basic question, but I cannot find an answer anywhere on SO.
I know that C/C++ do not have a byte
datatype.
I know that sizeof(char) == 1
.
I'm trying to store 12 transmissions, each of 96 bytes on Pebble, as transmitted from my Android app.
Due to limitation in the transmission size, I'm sending one at a time. Each one should be 'appended' to the last, as they should end up forming sequential space in memory, for reading as an image (one bit per pixel).
I'm trying to do something like this:
int transNum = 0;
uint8_t image[][] = new uint8t[12][12] //not sure about uint8_t, and I've forgotten how to do 'new' in C, I have to create just a pointer, and then malloc?
receivedHandler(DictionaryIterator *iter, void *context){
Tuple *receivedImage = dict_find(iter, KEY_IMG);
for (int i = 0; i < 12; i++) {
image[transNum][i] = receivedImage->value[i]->uint8_t;
}
transNum += 1; //this is in an implicit loop, since once done Pebble ACKs the transmission, and receivedHandler is called again by the next transmission
}
Am I even remotely close?
I think you need to malloc two times.
You can then treat image as a two-dimension array.
One thing I will add to this is be careful using just a
char
. Use something likeunsigned char
,signed char
, oruint8_t
when dealing with pure byte data. While a char is one byte I've seen loss of data because of it's use.You can allocate 12*96 byte of contiguous memory having 12 rows & 96 columns
also, a global array will do just fine
From what I understand, you are recieving data row wise ie 96 bytes at a time:
and access/set like this::
and to transfer all 96 bytes in one go:
The simplest solution to allocate the array you describe is:
However, based on your description " Each one should be 'appended' to the last, as they should end up forming sequential space in memory", that suggests you actually want:
and then you will just write your 12 transmission sequentially into that array.
This code you wrote:
isn't right,
uint8_t
is a data type, not a field name.Also, probably you want to do something with
image[i]
, rather thanimage[byteNum][i]
although I can't be more specific without knowing what theTupleType
is and how much you're expecting to find in eachTuple
.