Re: Generating struct .init at run time?

2020-07-02 Thread Ali Çehreli via Digitalmars-d-learn
On 7/2/20 10:51 AM, kinke wrote: On Thursday, 2 July 2020 at 16:51:52 UTC, kinke wrote: `= void` for members doesn't work and, I dare say, not work anytime soon if ever. I've quickly checked; `= void` for members has initialize-with-zeros semantics too, so with LDC, it's equivalent to `= 0`

Re: Generating struct .init at run time?

2020-07-02 Thread kinke via Digitalmars-d-learn
On Thursday, 2 July 2020 at 16:51:52 UTC, kinke wrote: `= void` for members doesn't work and, I dare say, not work anytime soon if ever. I've quickly checked; `= void` for members has initialize-with-zeros semantics too, so with LDC, it's equivalent to `= 0` but applicable to user-defined

Re: Generating struct .init at run time?

2020-07-02 Thread kinke via Digitalmars-d-learn
On Thursday, 2 July 2020 at 15:20:23 UTC, Ali Çehreli wrote: According to its date, it was written when I was working for Weka. Apparently, ldc took care of it for them after all. If so, then without them posting any issue beforehand or giving any feedback afterwards. > For recent LDC

Delegates and C++ FFI lifetimes

2020-07-02 Thread IGotD- via Digitalmars-d-learn
I have this runtime written in C++ that allows callbacks for various functionality. In C++ the callbacks are stored as a function pointer together with a void* that is passed as first argument. The void* can be a lot of things, for example the class pointer in C++. However, this is a bit

Re: Generating struct .init at run time?

2020-07-02 Thread Ali Çehreli via Digitalmars-d-learn
On 7/2/20 3:37 AM, kinke wrote: > On Thursday, 2 July 2020 at 07:51:29 UTC, Ali Çehreli wrote: >> Of course, the solution is to define members with '= void' > > Since when? https://issues.dlang.org/show_bug.cgi?id=11331 and your > https://issues.dlang.org/show_bug.cgi?id=16956 are still open.

Re: Generating struct .init at run time?

2020-07-02 Thread Ali Çehreli via Digitalmars-d-learn
On 7/2/20 2:37 AM, IGotD- wrote: > what on earth are those extra 800MB? I'm losing my mind. :) Of course it's just 8M. Too many digits for me to handle. :p > Also, this an obvious optimization that can be implemented, that the > program do an initialization loop instead of putting it in the

Re: Generating struct .init at run time?

2020-07-02 Thread Basile B. via Digitalmars-d-learn
On Thursday, 2 July 2020 at 10:37:27 UTC, kinke wrote: I don't think a struct should ever be that large, as it can probably only live on the heap anyway and only passed around by refs. I'd probably use a thin struct instead, containing and managing a `double[]` member (or

Re: Generating struct .init at run time?

2020-07-02 Thread kinke via Digitalmars-d-learn
On Thursday, 2 July 2020 at 07:51:29 UTC, Ali Çehreli wrote: Of course, the solution is to define members with '= void' Since when? https://issues.dlang.org/show_bug.cgi?id=11331 and your https://issues.dlang.org/show_bug.cgi?id=16956 are still open. For recent LDC versions, the 'solution'

Re: Generating struct .init at run time?

2020-07-02 Thread Patrick Schluter via Digitalmars-d-learn
On Thursday, 2 July 2020 at 07:51:29 UTC, Ali Çehreli wrote: Normally, struct .init values are known at compile time. Unfortunately, they add to binary size: [...] memset() is the function you want. The initializer is an element generated in the data segment (or in a read only segment) that

Re: Generating struct .init at run time?

2020-07-02 Thread IGotD- via Digitalmars-d-learn
On Thursday, 2 July 2020 at 07:51:29 UTC, Ali Çehreli wrote: Both asserts pass: S.init is 800M and is embedded into the compiled program. Not an answer to your problem but what on earth are those extra 800MB? The array size is 8MB so if the program would just copy the data it would just

Generating struct .init at run time?

2020-07-02 Thread Ali Çehreli via Digitalmars-d-learn
Normally, struct .init values are known at compile time. Unfortunately, they add to binary size: enum elementCount = 1024 * 1024; struct S { double[elementCount] a; } void main() { S s; assert(typeid(S).initializer.length == double.sizeof * elementCount);