class allocators should be more encapsulated
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Sat Dec 30 17:41:32 PST 2006
Luís Marques wrote:
> Frits van Bommel wrote:
>> Yes they do take parameters, and the reason is indeed to customize how
>> memory is allocated. But unless they throw an exception, they do have
>> to actually _allocate_ some memory. If they don't throw, the return
>> value must be a void* to a newly-allocated piece of memory.
>> So what I gather you're trying to do (potentially return a pointer to
>> an already-existing object) isn't acceptable behavior for a custom
>> allocator.
>
> You are right. If I return an existing object it will be initialized to
> default values. I guess that means the solution to a singleton pattern
> proposed by Burton Radons does not work
> (http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=D&artnum=14520)
>
>
> Still, it's a pity that "new ClassType()" cannot be used to
> transparently return an existing object (conditionally or not).
>
> --
> Luís Marques
Why should "new ClassType()" be able to return the same instance? What's
wrong with ClassType.getInstance() ? Or in your case
ClassType.getInstance("my string") ?
--
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d
mailing list