Re: How to do alligned allocation?

2022-09-30 Thread tsbockman via Digitalmars-d-learn
On Saturday, 1 October 2022 at 01:37:00 UTC, Steven Schveighoffer wrote: On 9/30/22 11:57 AM, Quirin Schroll wrote: Also, is the alignment of any type guaranteed to be a power of 2? In practice, it's not necessarily a power of 2, but it's *at least* 16 bytes. **Types** always require some

Re: Interfacing with Rust

2022-09-30 Thread mw via Digitalmars-d-learn
extern(C++)? Why do you think Rust export C++ linkage? And why do you think Rust export some kind of OO object model linkage? Do it in plain C style, you may make it work. As said, check how it's done in: https://code.dlang.org/packages/rust_interop_d

Re: Interfacing with Rust

2022-09-30 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 30 September 2022 at 06:25:33 UTC, Imperatorn wrote: On Friday, 30 September 2022 at 00:18:42 UTC, Ruby The Roobster wrote: On Thursday, 29 September 2022 at 16:07:59 UTC, mw wrote: On Thursday, 29 September 2022 at 16:02:43 UTC, Ruby The Roobster wrote: Is there any way one can

Re: How to do alligned allocation?

2022-09-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/30/22 11:57 AM, Quirin Schroll wrote: When I do `new void[](n)`, is that buffer allocated with an alignment of 1 or what are the guarantees? How can I set an alignment? Also, is the alignment of any type guaranteed to be a power of 2? In practice, it's not necessarily a power of 2, but

Re: How can I get the "owner" of a method?

2022-09-30 Thread Ali Çehreli via Digitalmars-d-learn
On 9/30/22 14:11, solidstate1991 wrote: > extern (C) public int registerDDelegate(alias Func, That can be a lambda that takes ClassType. I wrote the following along with place holder as I assumed them to be: class C { string s; void foo() { import std.stdio : writeln;

Re: How to do alligned allocation?

2022-09-30 Thread tsbockman via Digitalmars-d-learn
On Saturday, 1 October 2022 at 00:32:28 UTC, tsbockman wrote: alias Chunk = AliasSeq!(ubyte, ushort, uint, ulong, Chunk16)[shift]; Oops, I forgot that `ulong.alignof` is platform dependent. It's probably best to just go ahead and explicitly specify the alignment for all `Chunk`

Re: How to do alligned allocation?

2022-09-30 Thread tsbockman via Digitalmars-d-learn
On Friday, 30 September 2022 at 15:57:22 UTC, Quirin Schroll wrote: When I do `new void[](n)`, is that buffer allocated with an alignment of 1 or what are the guarantees? It is guaranteed an alignment of at least 1 because `void.alignof == 1` (and because that is the lowest possible integer

Re: Interfacing with basic C++ class

2022-09-30 Thread Ogi via Digitalmars-d-learn
On Thursday, 29 September 2022 at 12:49:06 UTC, Riccardo M wrote: On Thursday, 29 September 2022 at 11:13:15 UTC, Ogi wrote: So it turns out that D's structs are a much better match for C++'s classes in this case. But why is this? Can you elaborate? It must have to do with the fact that D

Re: How can I get the "owner" of a method?

2022-09-30 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 30 September 2022 at 21:11:48 UTC, solidstate1991 wrote: Let's say I have a class or an interface with a function, and I want to pass that to a template to generate another function (in this case one that passes it to a scripting engine, and allows it to be called from there).

How can I get the "owner" of a method?

2022-09-30 Thread solidstate1991 via Digitalmars-d-learn
Let's say I have a class or an interface with a function, and I want to pass that to a template to generate another function (in this case one that passes it to a scripting engine, and allows it to be called from there). Currently I have the following issues: 1. I have to pass the

Re: How to do alligned allocation?

2022-09-30 Thread mw via Digitalmars-d-learn
On Friday, 30 September 2022 at 16:23:00 UTC, mw wrote: On Friday, 30 September 2022 at 15:57:22 UTC, Quirin Schroll wrote: When I do `new void[](n)`, is that buffer allocated with an alignment of 1 or what are the guarantees? How can I set an alignment? Also, is the alignment of any type

Re: How to do alligned allocation?

2022-09-30 Thread mw via Digitalmars-d-learn
On Friday, 30 September 2022 at 15:57:22 UTC, Quirin Schroll wrote: When I do `new void[](n)`, is that buffer allocated with an alignment of 1 or what are the guarantees? How can I set an alignment? Also, is the alignment of any type guaranteed to be a power of 2?

How to do alligned allocation?

2022-09-30 Thread Quirin Schroll via Digitalmars-d-learn
When I do `new void[](n)`, is that buffer allocated with an alignment of 1 or what are the guarantees? How can I set an alignment? Also, is the alignment of any type guaranteed to be a power of 2?

What are best practices around toString?

2022-09-30 Thread christian.koestlin via Digitalmars-d-learn
Dear Dlang experts, up until now I was perfectly happy with implementing `(override) string toString() const` or something to get nicely formatted (mostly debug) output for my structs, classes and exceptions. But recently I stumbled upon

Re: Interfacing with Rust

2022-09-30 Thread Imperatorn via Digitalmars-d-learn
On Friday, 30 September 2022 at 00:18:42 UTC, Ruby The Roobster wrote: On Thursday, 29 September 2022 at 16:07:59 UTC, mw wrote: On Thursday, 29 September 2022 at 16:02:43 UTC, Ruby The Roobster wrote: Is there any way one can interface with Rust, such as with a struct, or a function? I know