|
|
This thread is locked; no one can reply to it.
|
1
2
|
| How to delete allocated memory at void pointer? |
|
Onewing
Member #6,152
August 2005
|
Quote: You're assuming that the linked list contains only objects of a specific type. What object can void* not point to? Quote: Also what if you want to store ints, for example? You'd need one pointer dereference every time a value is accessed while that's not the case if you'd use a template. And what's so bad about dereferencing? Also, void* and the next* is not all I store inside the linked list. I also store an int (ikey) for sorting purposes (or if you are simply storing ints) as well as a char* (ckey) if you need a char for some reason. Of course, this makes each node larger in size, but I don't think it's enough to make anything suffer. ------------ |
|
Evert
Member #794
November 2000
|
Quote: That's not a good use for void*
It is. |
|
Fladimir da Gorf
Member #1,565
October 2001
|
Quote: What object can void* not point to? That's my point indeed. When you need to access the data you need to know the real type of the objects. But you can't know it for sure because the type information is lost. Quote: And what's so bad about dereferencing? It's slower than a direct access. Quote: I also store an int (ikey) for sorting purposes (or if you are simply storing ints) as well as a char* (ckey) if you need a char for some reason. Of course, this makes each node larger in size, but I don't think it's enough to make anything suffer. Or you could store an object which contains all that data and a pointer to the real object or to store objects which inherit from the same virtual base class. Quote:
It is. But the question was (indirectly) if there's any good use for void pointers in C++. OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
|
Onewing
Member #6,152
August 2005
|
Quote:
It is. I wrote the linked list structure back in my C-hayday of early college years. When I gradually moved into C++, I just kept using it because it was easy to use. I guess I should rethink how to do it then...hmmmm... ------------ |
|
HoHo
Member #4,534
April 2004
|
Quote: And what's so bad about dereferencing? Compared to not dereferencing it is dead slow and takes more memory. When extreme performance is needed then there is a difference. On the other hand, if extreme performance is needed it is usually best to stay away from lists [edit] Quote: I guess I should rethink how to do it then...hmmmm... As I assume you already know how to code a linked list you might want to swich over to STL list. With that you automatically get all sorts of nifty things from <algorithm> header too. A slight speed improvement is also quite probable __________ |
|
Onewing
Member #6,152
August 2005
|
Quote: That's my point indeed.
I see. Well, I just got use to my class because it worked so well and I didn't really know I was losing that much performance. Of course, I never had a very big list so it's not like I'd notice a performance flaw anyway. My original concept of making the linked list structure was "store something in a generic list" (some_list->data = something) and "read information from the list" (dereference). Out of the few years I've been using it, I've never accidentally casted it to the wrong type when I dereferenced it. Of course, this is all old news now and I'm going to research STL and I guess, put my list to rest. Quote: As I assume you already know how to code a linked list you might want to swich over to STL list. Done and done. I'm gonna tinker around with this when I get a chance. Is this a good site to start from? ------------ |
|
HoHo
Member #4,534
April 2004
|
Quote: Is this a good site [msoe.edu] to start from? Seems to be. Though I usually just use whatever is first result from Google __________ |
|
Onewing
Member #6,152
August 2005
|
Quote: Though I usually just use whatever is first result from Google
It was. ------------ |
|
HoHo
Member #4,534
April 2004
|
googling for "c++ iostream" or "stl vector" come up with totally different sites. I usually just google for specific stuff and use several different sites for reference __________ |
|
Onewing
Member #6,152
August 2005
|
try "stl list" ------------ |
|
|
1
2
|