Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WifiS3 WiFiClient) Reduce memory allocations #407

Open
ondra-novak opened this issue Nov 30, 2024 · 2 comments
Open

(WifiS3 WiFiClient) Reduce memory allocations #407

ondra-novak opened this issue Nov 30, 2024 · 2 comments
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement type: imperfection Perceived defect in any part of project

Comments

@ondra-novak
Copy link

Embedded devices should avoid to use memory allocation - or limit allocations to minimum. Unfortunately, the code for WiFi does not honour this rule.

  • don't use std::string, use static allocated buffer
  • don't use std::make_shared - we have C++17, implementing copy constructors for every class is no longer required. WiFiClient can have preallocated buffer as member variable. The programmer can possibly choose to use std::make_shared for the whole WiFIClient instance, if it needs to share it by other objects.
  • typo: destroy_at_distructor
  • bug: the flag destroy_at_distructor is never used, destructor is empty.

WiFiClient::WiFiClient() : _sock(-1), destroy_at_distructor(true), rx_buffer(nullptr) {

@JAndrassy
Copy link
Contributor

The programmer can possibly choose to use std::make_shared for the whole WiFIClient instance, if it needs to share it by other objects.

no. this is Arduino not C++ 17. WiFiClient must be copyable in Arduino. for example server.available and server.accept return a copy.

please add to the title that this is about the WiFiS3 library. this platform has two WiFi libraries

@per1234 per1234 added type: imperfection Perceived defect in any part of project type: enhancement Proposed improvement topic: code Related to content of the project itself labels Nov 30, 2024
@ondra-novak ondra-novak changed the title (WiFiClient) Reduce memory allocations (WifiS3 WiFiClient) Reduce memory allocations Nov 30, 2024
@ondra-novak
Copy link
Author

Arduino is shipped with GCC-7 which defaults to C++17

for example server.available and server.accept return a copy

This is simple not true. Please learn C++
https://en.cppreference.com/w/cpp/language/copy_elision

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

3 participants