flyweight design pattern - need some explanation
-
hi, I'm reading about the flyweight design pattern. In my understanding it's basically something like 'use shared pointers/references to big objects in order to safe memory'. Example: I'm writing a website, that contains 1MB pictures all over it. All the pictures are the same. Now, instead of transferring the picture x times, I. transfer it only once and let the website content always refer to that already transferred picture. Am I right about that? The often used example with the letters and glyph does really confuse me here, so I'd like to recheck. I can't understand, why it would be better to have a referred letter instead of a simple char inside a class... I really appreciate any help here!! regards
-
hi, I'm reading about the flyweight design pattern. In my understanding it's basically something like 'use shared pointers/references to big objects in order to safe memory'. Example: I'm writing a website, that contains 1MB pictures all over it. All the pictures are the same. Now, instead of transferring the picture x times, I. transfer it only once and let the website content always refer to that already transferred picture. Am I right about that? The often used example with the letters and glyph does really confuse me here, so I'd like to recheck. I can't understand, why it would be better to have a referred letter instead of a simple char inside a class... I really appreciate any help here!! regards
-
You will need to be more specific about what you mean by "transferring". Are you talking about content in a web page? FTP? What? What / why 1 MB images? For display in a browser? Why not thumbnails?
Thank you for the answer! yes, I was assuming a web page. But apparently the example was not appropriate and therefore missleading. Maybe we should just skip the example. So the "flyweight" in the "flyweight" pattern refers small objects, that all share some heavy ressource?
-
Thank you for the answer! yes, I was assuming a web page. But apparently the example was not appropriate and therefore missleading. Maybe we should just skip the example. So the "flyweight" in the "flyweight" pattern refers small objects, that all share some heavy ressource?
-
Yes; I would agree with your last statement. "Small objects" that container references / pointers to "big" / data objects.