serge1 / ELFIO

ELFIO - ELF (Executable and Linkable Format) reader and producer implemented as a header only C++ library
http://serge1.github.io/ELFIO
MIT License
726 stars 157 forks source link

Add segment free_data function #127

Closed quic-egmc closed 12 months ago

quic-egmc commented 1 year ago

Allow for segment data to be freed to allow for reduced memory usage when dealing with large elf segments.

quic-egmc commented 1 year ago

@serge1 please take a look at this small enhancement and let me know if there's anything more I can describe, thanks!

quic-egmc commented 1 year ago

@serge1 just a reminder - this is really useful when dealing with files that contain multiple large ELF segments as it provides a way to minimize memory consumption by freeing segment data after it is used. Thanks again!

serge1 commented 1 year ago

Hi, Thank you for your submission! I'm out of the town at these days, returning back in two weeks. I'll review your changes upon my return.

serge1 commented 12 months ago

Accepted. Thank you very much!

serge1 commented 12 months ago

Unfortunately, it is possible to use this function only in condition that elfio object was loaded in 'lazy' mode. Otherwise, a second attempt to access segment's data will lead to a problem as the input stream is already closed/destroyed.

quic-egmc commented 12 months ago

Unfortunately, it is possible to use this function only in condition that elfio object was loaded in 'lazy' mode. Otherwise, a second attempt to access segment's data will lead to a problem as the input stream is already closed/destroyed.

Got it - in that case perhaps we should only allow this if is_lazy was set to begin with. That would also require that we do not clear is_lazy in load_data since we need to preserve it to indicate "stream is still open". Since I suspect the reason for clearing it was to prevent unnecessary re-loads of data a new flag like is_loaded may be required.