Re: Overloading new[]
- From: "Igor Tandetnik" <itandetnik@xxxxxxxx>
- Date: Tue, 24 Jan 2006 15:31:51 -0500
Victor Bazarov <v.Abazarov@xxxxxxxxxxxx> wrote:
> MyClass* arrayCreator(size_t howmany, int argument) {
> char *storage = new char[howmany * sizeof(MyClass)];
> for (int i = 0; i < howmany; ++i)
> new (storage + sizeof(MyClass) * i) MyClass(argument);
> return reinterpret_cast<MyClass*>(storage);
> }
>
> void arrayDisposer(MyClass* arr)
> {
> delete[] reinterpret_cast<char*>(arr);
> }
It would be prudent to run destructors before freeing the memory. And
for that, you would need to keep track of the number of elements
allocated.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
.
- Follow-Ups:
- Re: Overloading new[]
- From: Victor Bazarov
- Re: Overloading new[]
- References:
- Overloading new[]
- From: maynard
- Re: Overloading new[]
- From: Victor Bazarov
- Re: Overloading new[]
- From: maynard
- Re: Overloading new[]
- From: Victor Bazarov
- Overloading new[]
- Prev by Date: Re: Overloading new[]
- Next by Date: Re: Overloading new[]
- Previous by thread: Re: Overloading new[]
- Next by thread: Re: Overloading new[]
- Index(es):
Relevant Pages
|