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

Remove #include <iostream> to allow compiling for small embedded systems #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

timoscs
Copy link

@timoscs timoscs commented May 26, 2020

I'm using the library on a 128kB STM32F4 -processor, and #include brings in about 140kB of data, which obviously won't fit in the flash. Without iostream, this library increases code size by about 400 bytes when using pcg32, which is pretty ok (although could probably still be trimmed).

Admittedly it's a bit brute force to just remove the header inclusions, and that it works at all is based on all the iostream -related code being in templates, so that when they're not used there's no problem. If you do use them, you have to include yourself and the order does matter (I had to change one of the tests to make them compile).

Another approach would be to merge pull request #4 , switching the extras header to also use forward declarations.

Yet another approach, maybe more robust but less elegant, would be to #ifdef out the iostream headers if some flag (PCG_DONOTUSEIOSTREAM ? ) is defined.

Removing is not absolutely necessary, but I'm not sure what it's used for here, the only relevant part I could find is one use of placement new?

Timo Alho added 2 commits May 26, 2020 14:29
Admittedly it's a bit brute force to just remove the header inclusions, and that it works is based on all the iostream -related code being in templates, so that when they're not used there's no problem. Of you do use them, you have to include <iostream> yourself (and I'm not 100% sure that there won't be restrictions in order of includes).

Another approach, maybe more robust but less elegant, would be to #ifdef out the iostream headers if some flag (PCG_DONOTUSEIOSTREAM ? ) is defined

Removing <new> is not absolutely necessary, but I'm not sure what it's used for here, the only relevant part I could find is one use of placement new?
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

Successfully merging this pull request may close these issues.

1 participant