On Monday, 20 April 2015 at 21:36:35 UTC, Ali Çehreli wrote:
final class Foo {
uint id;
@nogc
this(uint id) {
this.id = id;
}
}
C reuse(C, T...)(ref C old, T ctorParams)
{
import std.conv;
import std.typetuple;
enum objectSize = __traits(classInstanceSize, C
On Monday, 20 April 2015 at 21:58:59 UTC, Ali Çehreli wrote:
On 04/20/2015 02:44 PM, Namespace wrote:
> Thank you. Do you mean this is worth a PR, to add this
> functionality to Phobos?
I am not familiar with such a need so I don't have a strong
opinion.
However, if an object needs to be emp
On 04/20/2015 02:44 PM, Namespace wrote:
> Thank you. Do you mean this is worth a PR, to add this
> functionality to Phobos?
I am not familiar with such a need so I don't have a strong opinion.
However, if an object needs to be emplaced on top of an existing one, I
can imagine that the origina
Thank you. Do you mean this is worth a PR, to add this
functionality to Phobos?
My current code looks like this:
http://dpaste.dzfl.pl/19b78a600b6c
On 04/20/2015 12:05 PM, Namespace wrote:
> I'm sorry if I annoy you
Not at all! :) Sorry for not responding earlier.
>, but I would really like to know how you would
> reuse already instantiated storage of an existing object.
>
> Example code:
>
> final class Foo {
> uint id;
>
>
On Sunday, 19 April 2015 at 21:17:18 UTC, Ali Çehreli wrote:
On 04/19/2015 09:04 AM, Namespace wrote:
> Is it somehow possible to reuse the memory of an object?
Yes, when you cast a class variable to void*, you get the
address of the object.
> @nogc
> T emplace(T, Args...)(ref T obj, auto re
It seems that D has currently no direct support to reuse object
memory.
D should add a new-placement syntax:
Foo f = new Foo(42);
new (f) Foo(23);
and/or should add an emplace overload which takes an object:
T emplace(T, Args...)(ref T obj, auto ref Args args) if (is(T ==
class
And if I have an already instantiated object?
Foo f = new Foo();
// reuse f's memory
Is there an nicer way to override the memory instead of:
void[] buf = (cast(void*) f)[0 .. __traits(classInstanceSize,
Foo)];
buf = typeid(Foo).init[]; // or: buf = f.classinfo.init[];
?
The
On 04/19/2015 09:04 AM, Namespace wrote:
> Is it somehow possible to reuse the memory of an object?
Yes, when you cast a class variable to void*, you get the address of the
object.
> @nogc
> T emplace(T, Args...)(ref T obj, auto ref Args args) nothrow if (is(T ==
> class)) {
There is already
Is it somehow possible to reuse the memory of an object?
My current idea is:
@nogc
T emplace(T, Args...)(ref T obj, auto ref Args args) nothrow if
(is(T == class)) {
if (obj is null)
return null;
enum size_t SIZE = __traits(classInstanceSize, T);
void[] buf = (cast(vo
10 matches
Mail list logo