Unmanaged - a D framework on github

D-ratiseur ThisAdressDoesntExist at nowhere.fr
Mon Mar 18 16:27:20 PDT 2013


On Sunday, 17 March 2013 at 15:20:04 UTC, Jakob Ovrum wrote:
> On Saturday, 16 March 2013 at 14:40:58 UTC, D-ratiseur wrote:
>> new is overriden in TUObject because the purpose of the 
>> library is to bypass the garbage collector and  to bypass the 
>> GC you have to override new and delete.(at least according to 
>> the manual: articles,mem managment).
>
> The documentation on this is old and misleading.
>
> Overloading of new and delete is deprecated (the delete 
> operator in its entirety is deprecated).
>
> Having them overloadable was not a very good idea. The current 
> approach is to have "new" always mean GC memory, which is why 
> there is no need for delete. This way, code that uses 'new' 
> won't break horribly or leak depending on the type involved, 
> important for generic code. Code that doesn't use the GC has to 
> be designed for it; you can't just remove the GC under 
> everyone's noses and expect things to work.
>
> For different kinds of memory, you should simply use a 
> different allocator. For example, here's a rough approximation 
> of a pair of functions using malloc/free for class allocation:
>
> T alloc(T)() if(is(T == class))
> {
> 	enum size = __traits(classInstanceSize, T);
> 	auto p = enforceEx!OutOfMemoryError(malloc(size));
> 	return emplace!T(p[0 .. size]);
> }
>
> void dealloc(T)(ref T obj) if(is(T == class))
> {
>     free(cast(void*)obj);
>     obj = null;
> }
>
> It can easily be overloaded to support all types.
>
> In the future, Phobos will have a custom memory allocator 
> library, which modules like std.container will use, though to 
> which extent is not clear (for example, will it also use the 
> custom allocator for exception objects?). Nevertheless it will 
> probably be a good base for other libraries to easily support 
> non-GC allocators.

Thx, that's some very usefull info...however curently "Unmanaged"
have its own leak tracer, basically it's a compiler switch that
allows to record every call to alloc(), realloc() and free().
Once again there must be a kind of misunderstanding about the
lib. It's made to bypass the GC...and it's not under everybody
nose ! I clearly state about this and the code is made for that
purpose.
Anyway, it's possible that I've been, until now, a bit naive
about the manual...For example in the win chm, object classinfo
pretends to have this member:
---
const(MemberInfo[]) getMembers(in char[] name);
Search for all members with the name 'name'. If name[] is null,
return all members".
---
Which is the most mysterious method ever...since it seems not
exist at all... ;)


More information about the Digitalmars-d-announce mailing list