On Thursday, 5 January 2023 at 05:59:26 UTC, Ali Çehreli wrote:
On 1/4/23 20:04, Paul wrote:
>> (Again, there is no problem here; we are just learning.)
>> Ali
>
> Do I have this much right?
> ..with this output?
Looks good to me.
While we're here, you can force the class objects to be on the
On Thursday, 5 January 2023 at 17:23:39 UTC, H. S. Teoh wrote:
On Thu, Jan 05, 2023 at 06:32:47AM +, areYouSureAboutThat
Also, I cannot read hex,
[...]
IMNSHO, anyone who claims to be a programmer should at least
know that much.
??
Well, like all, I learnt this at uni. .. as well as
On Thursday, 5 January 2023 at 05:59:26 UTC, Ali Çehreli wrote:
While we're here, you can force the class objects to be on the
stack as well:
scope MyClassVar1 = new MyClass();
I replaced 'auto' with 'scope'.
Ali
Very interesting. Thanks Ali.
On Thu, Jan 05, 2023 at 06:32:47AM +, areYouSureAboutThat via
Digitalmars-d-learn wrote:
[...]
> Second, to be sure your getting the correct results, it would be nice
> if there was a 'category of type' in std.traits for:
>
> isAllocatedOnStack
> isAllocatedOnHeap
>
> As it is, your just
On Thursday, 5 January 2023 at 04:04:39 UTC, Paul wrote:
..
Do I have this much right?
...
First, i would say, add @safe to your main.
@safe void main() ...
Then you will see you are treading on dangerous waters ;-)
Second, to be sure your getting the correct results, it would be
nice if
On 1/4/23 20:04, Paul wrote:
>> (Again, there is no problem here; we are just learning.)
>> Ali
>
> Do I have this much right?
> ..with this output?
Looks good to me.
While we're here, you can force the class objects to be on the stack as
well:
scope MyClassVar1 = new MyClass();
I
(Again, there is no problem here; we are just learning.)
Ali
Do I have this much right?
```d
import std.stdio, std.traits;
class MyClass {char c;}
void main() {
auto MyInt = 1;
writeln("The address of MyInt is : ",," (stack)");
auto MyClassVar1 = new MyClass();
On 1/4/23 13:43, H. S. Teoh wrote:
> You do realize that the compiler is free to reorder local variables on
> the stack, right? ;-)
Of course. :)
I was trying different strategies to catch the compiler (dmd here) in a
single act of 8-byte object alignment as reported by .alignof.
Another
On Wed, Jan 04, 2023 at 01:20:12PM -0800, Ali Çehreli via Digitalmars-d-learn
wrote:
> On 1/4/23 12:02, Steven Schveighoffer wrote:
> > On 1/4/23 2:27 PM, Ali Çehreli wrote:
>
> >> I put the objects into a 2-length
> >> static array but the difference was still 0x20. (?)
> >
> > Are you putting
On 1/4/23 12:02, Steven Schveighoffer wrote:
> On 1/4/23 2:27 PM, Ali Çehreli wrote:
>> I put the objects into a 2-length
>> static array but the difference was still 0x20. (?)
>
> Are you putting the class *references* in a 2-length static array?
I lied. As I could not put the objects in a
On 1/4/23 2:27 PM, Ali Çehreli wrote:
On 1/4/23 10:48, H. S. Teoh wrote:
> Allocations are not necessarily consecutive; the GC may have its own
> strategy of allocation that doesn't follow a linear sequence.
That was one of my guesses. So, I put the objects into a 2-length static
array but
On 1/4/23 11:27, Ali Çehreli wrote:
> writeln("hidden 0: ", hiddenValue(addr, 0));
> writeln("hidden 1: ", hiddenValue(addr, 1));
Silly me! :) Those members have names:
writeln("__vptr : ", obj.__vptr);
writeln("__monitor : ", obj.__monitor);
On 1/4/23 10:48, H. S. Teoh wrote:
> Allocations are not necessarily consecutive; the GC may have its own
> strategy of allocation that doesn't follow a linear sequence.
That was one of my guesses. So, I put the objects into a 2-length static
array but the difference was still 0x20. (?)
>
On Wed, Jan 04, 2023 at 09:51:05AM -0800, Ali Çehreli via Digitalmars-d-learn
wrote:
> On 1/3/23 20:01, Paul wrote:
>
> > Size Alignment Type
> > =
> >17 8 MyClass
> >
> > MyClassObj1 MyClassObj2
> > 27727202000 27727202020
> > ```
> > If my
On 1/3/23 20:01, Paul wrote:
> Size Alignment Type
> =
>17 8 MyClass
>
> MyClassObj1 MyClassObj2
> 27727202000 27727202020
> ```
> If my size is 17 bytes and my alignment is 8 bytes, shouldn't my
> MyClassObj2 in this example be @
matheus, using dmd64 on my laptop to compile and run this:
```d
import std.stdio, std.traits;
class MyClass {char[16] c;}
void main() {
writeln(" Size Alignment Type\n",
"=");
size_t size = __traits(classInstanceSize, MyClass);
size_t alignment
Thank you, Teoh, Ali, & Matheus
On 1/1/23 01:01, Paul wrote:
> ...on my laptop it prints...
> ```
> Size Alignment Type
> =
> 9 4 MyClass
>
> 4FFB20 4FFB24
> ```
> If the size of MyClass is 9 bytes why do MyClassO1 & O2 addresses only
> differ by 4 bytes?
As matheus said, classes
On Sunday, 1 January 2023 at 09:01:24 UTC, Paul wrote:
...
If the size of MyClass is 9 bytes why do MyClassO1 & O2
addresses only differ by 4 bytes?
Because those addresses(4FFB20 4FFB24) are the addresses of
the class **variables**, not the addresses of the **objects**
themselves?
Thanks all. Yes it seems my understanding and "D" vocabulary are
still a bit confused.
So I'm taking a D course online and was trying to verify what I
was learning. The course example printed out the size and
alignment of types...something close to this:
```d
import std.stdio;
import
On 12/31/22 16:35, Paul wrote:
> Can I acquire the address of a class object,
Answering that question literally, yes, you can by casting the class
variable to void*. But note: 'class object' means the instance of class
in D.
> not a class variable (i.e.
> the instantiations of the class)
D
On Sun, Jan 01, 2023 at 12:35:40AM +, Paul via Digitalmars-d-learn wrote:
> Hello. Thanks for any assistance.
>
> Can I acquire the address of a class object, not a class variable
> (i.e. the instantiations of the class) but the object definition
> itself?
>
> ```d
> class MyClass {char c}
22 matches
Mail list logo