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

chore: memory allocations improvements #467

Open
XavierChanth opened this issue Dec 9, 2024 · 2 comments
Open

chore: memory allocations improvements #467

XavierChanth opened this issue Dec 9, 2024 · 2 comments
Assignees

Comments

@XavierChanth
Copy link
Member

  • Switch to static memory allocations where it makes sense
  • I made some mistakes in telling the team to use heap memory in place where it wasn't necessary to.
@XavierChanth XavierChanth self-assigned this Dec 9, 2024
@XavierChanth
Copy link
Member Author

See also #466

@XavierChanth
Copy link
Member Author

So I think there's a fundamental problem with the way the connection layer provides memory back to the application.

We currently have to:

  • allocate memory to read from mbedtls
  • then allocate again to pass the memory into the application layer with the parts of the message we don't want stripped out.
  • then whatever allocations happen to consume that message further.

Instead, we should try to allocate that message once, and use indices and carefully replace delimiters with null terminators.

For example to consume the message:

struct message {
  unsigned char* buffer;
  uint32_t buffer_len; // length of the entire buffer
  uint32_t payload_idx; // index of the actual payload contents
}

This struct is much more efficient to pass around, and other structs can consume it, copying just the indices rather than the whole buffer contents.

Buffer is still a pointer to the start of memory allocation, so it can still be used to free at the end.

To get the actual payload contents for example, the address for it would be buffer + payload_idx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant