Coder Social home page Coder Social logo

Comments (7)

strud avatar strud commented on July 20, 2024

Hi sreekants,

I had this issue recently and yes you must call rc.close() every cycle to release the memory.

I have also suggested it be added to the example code.

Maybe a better approach is to allocate the maximum allowable per message ie 256 bytes and then leave it allocated for ever?

from ebyte_lora_e22_series_library.

sreekants avatar sreekants commented on July 20, 2024

Hi sreekants,

I had this issue recently and yes you must call rc.close() every cycle to release the memory.

I have also suggested it be added to the example code.

Maybe a better approach is to allocate the maximum allowable per message ie 256 bytes and then leave it allocated for ever?

I like the idea of a pre-allocated buffer managed by the library. That would be a good fix with backward compatibility if the close() function has an empty body.

from ebyte_lora_e22_series_library.

xreef avatar xreef commented on July 20, 2024

Hi all,
no, the ResponseContainer doesn't need a close function because there isn't a pointer but directly a complex variable.
Bye Renzo

from ebyte_lora_e22_series_library.

sreekants avatar sreekants commented on July 20, 2024

Hi Renzo,
Where is the corresponding free() to the buffer allocated on line 780? The pointer rc.data holds a pointer to this buffer, but the only call releasing this buffer is ResponseContainer::close(). However, I do not see it being called.

rc.data = malloc(size);

Can you explain how the heap is managed correctly with the library?

(We arrived at this problem because we were transmitting 220 byte frame over LoRa E22 in our software and when we monitored the heap it fell from 180Kb, steadily to 70kb as our stress tests ran through a few hours.)

from ebyte_lora_e22_series_library.

xreef avatar xreef commented on July 20, 2024

Hi @sreekants,
you select the ResponseStructContainer that needs close

ResponseStructContainer LoRa_E22::receiveMessageComplete(const uint8_t size, bool rssiEnabled){
ResponseStructContainer rc;
rc.data = malloc(size);
rc.status.code = this->receiveStruct((uint8_t *)rc.data, size);
if (rc.status.code!=E22_SUCCESS) {
return rc;
}
if (rssiEnabled){
char rssi[1];
this->serialDef.stream->readBytes(rssi, 1);
rc.rssi = rssi[0];
}
this->cleanUARTBuffer();
return rc;
}

and It had It

struct ResponseStructContainer {
void *data;
byte rssi;
ResponseStatus status;
void close() {
free(this->data);
}
};

but the ResponseContainer doesn't have and doesn't need a close.

struct ResponseStructContainer {
void *data;
byte rssi;
ResponseStatus status;
void close() {
free(this->data);
}
};
struct ResponseContainer {
String data;
byte rssi;
ResponseStatus status;
};

Bye Renzo

from ebyte_lora_e22_series_library.

sreekants avatar sreekants commented on July 20, 2024

Yes, I understand now. I stand corrected. Your samples use ResponseContainer. So they do not need a close(). You are correct there.

In our usecase, however, we are sending binary data over LoRa. The ResponseContainer is suitable only for string data. This is why we end up calling receiveMesssageComplete(). As stated, each call allocates a buffer, fragmenting memory, even if the close() function is called. Is there a better way to allow the use of a preallocated buffer so we don't have to malloc() every loop?

from ebyte_lora_e22_series_library.

xreef avatar xreef commented on July 20, 2024

Ahhh ok, now I understand,
mmm... no I don't think about that, but It's an interesting feature and can be a good enhancement.
I think of a solution.
If you have some suggestions write here.
Bye Renzo

from ebyte_lora_e22_series_library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.