|
ECS-L Home Automation and Security Archives |
learn more
| view messages for this
month | NetBloc® | terms of use | search
subject (prev) or (next) |
time (prev) or (next) |
author (prev) or (next) |
view more subjects
Subject: From: Date: | Re: [ECS] C++ reallocate ? Ingo Pakleppa Wed, 29 Sep 1999 17:19:19 -0700 |
Realloc is considered a very non-OO thing. Thus, you can't do it with new,
which is mostly intended for objects and other type-safe allocations.
If all you need is a memory buffer of a given size, you can continue to use
malloc and realloc.
However, realloc can also be a very time-consuming and potentially also
dangerous operation, so I would suggest you instead allocate enough memory
to begin with, and simply not use all of it.
If you use realloc to reduce the size of a buffer, simply don't do it -
it's essentially a no-op to begin with. If you use realloc to increase the
buffer size, you would typically be better off just allocating a larger
buffer to begin with. Realloc may need to move the memory to another
location. That means that any pointers you keep to it would become invalid
(thus the statement "dangerous operation", and it's just as time-consuming
as if you copied it manually.
Ingo
At 06:56 AM 9/29/99 -0700, Mark Gilmore wrote:
>To C++ programmers:
>In studying C++, I am looking at replacing my malloc()
>calls with "new", but I can find no description (in
>my C++ book or in MS C++) on how to RE-allocate mem
>(which I use extensively via realloc()).
>How is this handled in C++ ? Thanks.
>--
>Mark Gilmore
>Omnipotence (ECS home automation software)
>http://www.usit.com/omnip
>423-745-0026
subject (prev) or (next) |
time (prev) or (next) |
author (prev) or (next) |
view more subjects