Path Class memory usage

I am drawing a bunch of paths in my app, which are re-calculated whenever the window is resized. I noticed a spike in the memory usage whenever the app is resized, and after investigating a bit, It is attributed to the “preallocateSpace (x);” call in every Path method that adds to the path. Altho it is a small bump in memory usage, and it drops back down after the app has finished resizing, it still happens. It got me thinking about if it’s possible to create a cache of some kind for the paths. Maybe like a subclass of Path where if you know how many elements your path will have, it’ll create a memory pool that won’t grow or shrink for that particular Path subclass object? So that way whenever you recalculate your paths, it doesn’t need to ask for new memory every time you path.clear() and then redefine the path.

1 Like

Well, if you’re really hammering the path-creation code then you’ll get a performance boost by calling preallocateSpace yourself with a big number before actually generating your paths. No need for subclasses or anything fancy IMHO.

It already does that - have a look at the code in Path::clear(), and you’ll see that it just resets a flag and leaves the currently allocated memory there for re-use.