H
Howard
I'm converting some old handle-based code, updating it to use stl
containers. I've wondering if someone can suggest the proper container type
for the following:
I've got a bunch of bitmaps (stored as resources in a Windows program), each
identified by a resource ID (a short integer, say). I'll be loading them
all into memory and creating my own object (CachedPic) to hold (and later
manipulate) each image. So what I'll have is an association between a short
and a CachedPic.
I'll only be inserting them all once, deleting once when the program ends,
and retrieving pointers (references? iterators?) to the objects often. I
need fast access via the id.
I'm thinking that maybe a map<short,CachedPic> would be the answer, but I'm
not sure. Maybe map<short,CachedPic*>?
I don't really need to sort the objects, except that that probably makes
retrieval faster, I'd assume. Which is why I'm thinking map. Usually I use
vectors instead of arrays, but I thought maybe since I need to retrieve
specific items based on an id, a map might be faster.
I think I need to get a better book on the stl, since the one I have (the
C++ Programming Lanugage, Stroustrup) is technically complete but short on
examples (at least ones I find useful, in this case). But in the meantime,
if someone could give me their opinion on what container I should use, and
whether to store the object or a pointer there, I'd appreciate it.
Many thanks,
Howard
containers. I've wondering if someone can suggest the proper container type
for the following:
I've got a bunch of bitmaps (stored as resources in a Windows program), each
identified by a resource ID (a short integer, say). I'll be loading them
all into memory and creating my own object (CachedPic) to hold (and later
manipulate) each image. So what I'll have is an association between a short
and a CachedPic.
I'll only be inserting them all once, deleting once when the program ends,
and retrieving pointers (references? iterators?) to the objects often. I
need fast access via the id.
I'm thinking that maybe a map<short,CachedPic> would be the answer, but I'm
not sure. Maybe map<short,CachedPic*>?
I don't really need to sort the objects, except that that probably makes
retrieval faster, I'd assume. Which is why I'm thinking map. Usually I use
vectors instead of arrays, but I thought maybe since I need to retrieve
specific items based on an id, a map might be faster.
I think I need to get a better book on the stl, since the one I have (the
C++ Programming Lanugage, Stroustrup) is technically complete but short on
examples (at least ones I find useful, in this case). But in the meantime,
if someone could give me their opinion on what container I should use, and
whether to store the object or a pointer there, I'd appreciate it.
Many thanks,
Howard