Skip to content

Buffers #2

@carlesaraguz

Description

@carlesaraguz

TX.c, transmittingThread:

There's an excessive use of memory in intermediary buffers. Lines 120 to 141 simply copy the contents of the global buffers to an intermediary one. However, this temporal buffer (imagebuffer) is never used for anything other than moving data. Instead, imagebuffer is copied into enc_symbols_tab in line 240.

Setting aside the memory inefficiency, there's an implementation aspect I don't understand. Let me try to show it here:

imagebuffer has 1084000 positions of data copied from buffer 1 or 2, plus 1 position to store the size. That's 1084001 positions (unsigned int), not bytes (size_t). In L225 there a loop that copies this data to enc_symbols_tab:

/* --- symb_sz_8 = 1084;  imagefilelen = bufferSize = 1084 * 1000 --- */
k=((imagefilelen + 1)/symb_sz_8)+1; /* = 1001.000922509 ~= 1001 */
/* (...) */
for (esi = 0; esi < k; esi++ ) {
    /* (...) */
    memcpy(enc_symbols_tab[esi], imagebuffer+(esi*symb_sz_32), symb_sz_8);
}

Your loop moves accross imagebuffer in steps of 271, but copies 1084 positions every time. Therefore, when esi is equal to k-1 = 1000, memcpy is equivalent to:

memcpy(enc_symbols_tab[1000], imagebuffer+(271000), 1084);

Positions 271000 to 272083 (both included) are copied to enc_symbols_tab and the loop exits. However, there's still data in positions 272084 to 1084001 which has not been copied elsewhere. It is true that enc_symbols_tab will have k * 1084 positions (1085084) copied, but some of those registers are overlapped and redundant.

Is there a reason for that? Am I misunderstanding the code or is just a feature implemented like this on purpose?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions