B
Bartosz Wiklak
Hi, I hope this question is not too general and I understand that is
was asked partially in many places.
I'm always surprised reading posts at this group concerning manual
memory allocation, pointers, especially void* pointers.
People write sometimes that "there is nothing bad in void*", manual
pointer manipulations is ok and so on.
I have many old habits, I'm always tempted to use malloc rather than
new[] etc but since I'm not involved in scientific programming where
programs were rather short and topic was far more complicated than the
software, and I work on bigger projects where maintenance is a big
issue I hate manual memory allocation.
Please don't get me wrong, I worked in Java for some time and it's
garbage collector driven me crazy but when the overload of automatic
memory management is only several percent of time comparing to manual
management I would like to use it.
What are the general patters used to get rid of manual memory
allocation and management? I'm talking about using vectors instead of
tables, or generally using RAII. What are the pitfalls?
For example, for all time I used a pattern of creating a single object
and then, in containers and methods, just using a pointer to that
object. This gave me many problems when destroying the object,
ensuring that all references are up to date.
On the other hand, I still worry that if I just use an object instance
in all places ( like containers ) I'll end with memory filled up with
many instances of the same object.
I thought that shared_ptr would be a good idea but I would't like to
get used to boost to much as it is forbidden to use it in many
companies.
Do you have the same problems? What are your solutions?
Regs,
Bartek
was asked partially in many places.
I'm always surprised reading posts at this group concerning manual
memory allocation, pointers, especially void* pointers.
People write sometimes that "there is nothing bad in void*", manual
pointer manipulations is ok and so on.
I have many old habits, I'm always tempted to use malloc rather than
new[] etc but since I'm not involved in scientific programming where
programs were rather short and topic was far more complicated than the
software, and I work on bigger projects where maintenance is a big
issue I hate manual memory allocation.
Please don't get me wrong, I worked in Java for some time and it's
garbage collector driven me crazy but when the overload of automatic
memory management is only several percent of time comparing to manual
management I would like to use it.
What are the general patters used to get rid of manual memory
allocation and management? I'm talking about using vectors instead of
tables, or generally using RAII. What are the pitfalls?
For example, for all time I used a pattern of creating a single object
and then, in containers and methods, just using a pointer to that
object. This gave me many problems when destroying the object,
ensuring that all references are up to date.
On the other hand, I still worry that if I just use an object instance
in all places ( like containers ) I'll end with memory filled up with
many instances of the same object.
I thought that shared_ptr would be a good idea but I would't like to
get used to boost to much as it is forbidden to use it in many
companies.
Do you have the same problems? What are your solutions?
Regs,
Bartek