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

Add keep_resident flag to Image for raw pixel data #3

Closed
ldicker83 opened this issue Jul 9, 2016 · 3 comments
Closed

Add keep_resident flag to Image for raw pixel data #3

ldicker83 opened this issue Jul 9, 2016 · 3 comments

Comments

@ldicker83
Copy link
Member

Currently, if we load another copy of an Image that's already available in the Renderer's texture list, all the basic data is copied to the new Image but the raw pixel data is not.

I modified the code for a usage edge case I ran into while using NAS2D for another project. The raw pixel data is now loaded regardless of whether or not the texture has already been created.

This solves the immediate problem in the project that ran into this issue (using pixelColor()) but is not ideal for regular use as it's a lot slower for load times and it's also very memory inefficient.

I want to modify the Image class to take a boolean value, keep_resident or stay_resident or something along those lines that instructs an Image to load a copy of the raw pixel data. 99% of uses of Image won't need this functionality so this will improve memory efficiency.

The modification should be done through a bool value in the Image c'tors. A default value should be provided so that current use doesn't break when updating NAS2D.

@ldicker83
Copy link
Member Author

I had a similar issue with the Music object and I'm realizing that having a stay_resident flag isn't going to really solve the issue and is a non-elegant solution to the problem.

The real solution is to also store a pointer to the raw data along with the reference counting so that copied objects can gain access to the data in said pointer. This way only one copy of the raw data is ever loaded and stays resident until all references are released after which the raw data is finally deallocated.

1 similar comment
@ldicker83
Copy link
Member Author

I had a similar issue with the Music object and I'm realizing that having a stay_resident flag isn't going to really solve the issue and is a non-elegant solution to the problem.

The real solution is to also store a pointer to the raw data along with the reference counting so that copied objects can gain access to the data in said pointer. This way only one copy of the raw data is ever loaded and stays resident until all references are released after which the raw data is finally deallocated.

@ldicker83
Copy link
Member Author

Killing this idea, no longer a need. All images keep their pixel data resident but they now only keep one copy of the pixel data no matter how many times it's loaded.

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