Re: Member access of __gshared global object

2014-08-06 Thread hane via Digitalmars-d-learn
On Wednesday, 6 August 2014 at 04:14:51 UTC, Puming wrote: 1. The only way that I can initialize it is to assign a value. But I want to initialize an empty AA, is that possible? workaround: string[string] aa; assert(aa is null); aa[""] = ""; aa.remove(""); assert(aa !is null);

Re: Member access of __gshared global object

2014-08-06 Thread via Digitalmars-d-learn
On Wednesday, 6 August 2014 at 04:14:51 UTC, Puming wrote: On Thursday, 31 July 2014 at 10:22:28 UTC, Marc Schütz wrote: On Thursday, 31 July 2014 at 02:03:37 UTC, Puming wrote: 1. Are AAs reference type? if so, why does the compiler copy it? This is probably your problem. They are reference

Re: Member access of __gshared global object

2014-08-05 Thread Puming via Digitalmars-d-learn
On Thursday, 31 July 2014 at 10:22:28 UTC, Marc Schütz wrote: On Thursday, 31 July 2014 at 02:03:37 UTC, Puming wrote: 1. Are AAs reference type? if so, why does the compiler copy it? This is probably your problem. They are reference types, but initially that reference is `null`. When you wri

Re: Member access of __gshared global object

2014-07-31 Thread via Digitalmars-d-learn
On Thursday, 31 July 2014 at 02:03:37 UTC, Puming wrote: 1. Are AAs reference type? if so, why does the compiler copy it? This is probably your problem. They are reference types, but initially that reference is `null`. When you write: auto cmds = CONFIG.commands; `cmds` contains a copy

Re: Member access of __gshared global object

2014-07-30 Thread Daniel Kozak via Digitalmars-d-learn
V Thu, 31 Jul 2014 02:03:35 + Puming via Digitalmars-d-learn napsáno: > Hi, > > I'm writing this global Config class, with an AA member: > > ```d > module my.config; > > class Config > { > Command[string] commands; > } > > __gshared Config CONFIG; > ``` > > and initialize it in anot

Member access of __gshared global object

2014-07-30 Thread Puming via Digitalmars-d-learn
Hi, I'm writing this global Config class, with an AA member: ```d module my.config; class Config { Command[string] commands; } __gshared Config CONFIG; ``` and initialize it in another module: ```d module my.app; import my.config; void main() { CONFIG = new Config(); CONFIG.command

Re: How to copy an object to separate allocated memory?

2014-07-24 Thread Gary Willoughby via Digitalmars-d-learn
true size of an object: MyClass* buffer = cast(MyClass*)GC.calloc(__traits(classInstanceSize, MyClass) * 10); That got me thinking, how would i actually 'fill' this memory with instances of that class? std.conv.emplace: http://dlang.org/phobos/std_conv.html#.emplace Wow, t

Re: How to copy an object to separate allocated memory?

2014-07-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 17:07:29 +, Justin Whear wrote: > On Thu, 24 Jul 2014 17:05:17 +, Gary Willoughby wrote: > >> I was reading Ali's book (http://ddili.org/ders/d.en/index.html) >> and saw this piece of code on how to get the true size of an object: >> >

Re: How to copy an object to separate allocated memory?

2014-07-24 Thread Daniel Gibson via Digitalmars-d-learn
Am 24.07.2014 19:05, schrieb Gary Willoughby: I was reading Ali's book (http://ddili.org/ders/d.en/index.html) and saw this piece of code on how to get the true size of an object: MyClass* buffer = cast(MyClass*)GC.calloc(__traits(classInstanceSize, MyClass) * 10); That got me thinking

Re: How to copy an object to separate allocated memory?

2014-07-24 Thread John Colvin via Digitalmars-d-learn
On Thursday, 24 July 2014 at 17:05:18 UTC, Gary Willoughby wrote: I was reading Ali's book (http://ddili.org/ders/d.en/index.html) and saw this piece of code on how to get the true size of an object: MyClass* buffer = cast(MyClass*)GC.calloc(__traits(classInstanceSize, MyClass)

How to copy an object to separate allocated memory?

2014-07-24 Thread Gary Willoughby via Digitalmars-d-learn
I was reading Ali's book (http://ddili.org/ders/d.en/index.html) and saw this piece of code on how to get the true size of an object: MyClass* buffer = cast(MyClass*)GC.calloc(__traits(classInstanceSize, MyClass) * 10); That got me thinking, how would i actually 'fill' th

Re: How to copy an object to separate allocated memory?

2014-07-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 17:05:17 +, Gary Willoughby wrote: > I was reading Ali's book (http://ddili.org/ders/d.en/index.html) > and saw this piece of code on how to get the true size of an object: > > MyClass* buffer = cast(MyClass*)GC.calloc(__traits(classInstanceSize

Re: is there any way for an object to make it self no longer usable

2014-07-19 Thread Kagamin via Digitalmars-d-learn
You can also try class invariant.

Re: is there any way for an object to make it self no longer usable

2014-07-19 Thread Kagamin via Digitalmars-d-learn
On Saturday, 19 July 2014 at 17:05:27 UTC, Sean Campbell wrote: surely not by writing another class with wrapper methods for the existing one. If you don't want to write the class, you can write a generator for it. See BlackHole wrapper for an example.

Re: is there any way for an object to make it self no longer usable

2014-07-19 Thread Kagamin via Digitalmars-d-learn
On Saturday, 19 July 2014 at 17:28:13 UTC, Frustrated wrote: If you do this you are potentially asking for a lot of access violation errors or undefined behavior. Of course, the object should not be used after destruction. The trick is to reliably diagnose it. If such uses are not

Re: is there any way for an object to make it self no longer usable

2014-07-19 Thread Frustrated via Digitalmars-d-learn
On Saturday, 19 July 2014 at 12:02:50 UTC, Sean Campbell wrote: is there any way for an object to make it self no longer usable? eg class someclass { string somevalue; bool someflag; int somelength; this (value,length,flag) { somevalue = value

Re: is there any way for an object to make it self no longer usable

2014-07-19 Thread Sean Campbell via Digitalmars-d-learn
On Saturday, 19 July 2014 at 13:46:08 UTC, Kagamin wrote: You can encapsulate it in a wrapper, which will control access to the object and reject if necessary. how ? surely not by writing another class with wrapper methods for the existing one.

Re: is there any way for an object to make it self no longer usable

2014-07-19 Thread Kagamin via Digitalmars-d-learn
You can encapsulate it in a wrapper, which will control access to the object and reject if necessary.

is there any way for an object to make it self no longer usable

2014-07-19 Thread Sean Campbell via Digitalmars-d-learn
is there any way for an object to make it self no longer usable? eg class someclass { string somevalue; bool someflag; int somelength; this (value,length,flag) { somevalue = value; someflag = flag; somelength

Re: lazy construction of an immutable object

2014-07-16 Thread Meta via Digitalmars-d-learn
On Wednesday, 16 July 2014 at 00:38:46 UTC, Puming wrote: 3. define all classes and use template magic to generate companion builders just like protobuffer does. But that would be complicated and I don't know how to do it. Do you have any suggestion for this approach? This would probably be a

Re: lazy construction of an immutable object

2014-07-15 Thread Jason den Dulk via Digitalmars-d-learn
the docs, it does what 'freeze' does, and is considered idiomatic. But the draw back is that you can't garanteed that the mutable object is never used. I got the impression that assumeUnique has the same problem. Regards

Re: Handle to some object, call its methods

2014-07-15 Thread Anonymous via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 17:06:14 UTC, Ali Çehreli wrote: On 07/15/2014 09:39 AM, Anonymous wrote: > struct Subscription { > const Object handle; > private immutable size_t index; > @disable this(); > private this(Object o, size_t i) { >

Re: lazy construction of an immutable object

2014-07-15 Thread Puming via Digitalmars-d-learn
class at compile time? There's no real idiomatic approach, I think, because this is somewhat unexplored territory. I'd say constructing the object inside a pure method so it can be implicitly cast to immutable is more typesafe, but if you're storing the immutable reference to t

Re: lazy construction of an immutable object

2014-07-15 Thread Meta via Digitalmars-d-learn
c approach, I think, because this is somewhat unexplored territory. I'd say constructing the object inside a pure method so it can be implicitly cast to immutable is more typesafe, but if you're storing the immutable reference to the object in a class or struct, it can only be initiali

Re: Handle to some object, call its methods

2014-07-15 Thread Ali Çehreli via Digitalmars-d-learn
On 07/15/2014 09:39 AM, Anonymous wrote: > struct Subscription { > const Object handle; > private immutable size_t index; > @disable this(); > private this(Object o, size_t i) { > handle = o; > index = i; > } > } > > I&#

Handle to some object, call its methods

2014-07-15 Thread Anonymous via Digitalmars-d-learn
struct Subscription { const Object handle; private immutable size_t index; @disable this(); private this(Object o, size_t i) { handle = o; index = i; } } I'd like this to be constructed with a handle to some object

Re: lazy construction of an immutable object

2014-07-15 Thread Puming via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 13:59:24 UTC, Ali Çehreli wrote: On 07/15/2014 05:20 AM, Puming wrote: I found another way to do this, namely first create a class that is mutable, then cast it to an immutable object before using it. ```d class A { int a; B b; this(int a, int b

Re: lazy construction of an immutable object

2014-07-15 Thread Ali Çehreli via Digitalmars-d-learn
On 07/15/2014 05:20 AM, Puming wrote: I found another way to do this, namely first create a class that is mutable, then cast it to an immutable object before using it. ```d class A { int a; B b; this(int a, int b) { this.a = a; this.b = new B(b

Re: lazy construction of an immutable object

2014-07-15 Thread Puming via Digitalmars-d-learn
I found another way to do this, namely first create a class that is mutable, then cast it to an immutable object before using it. ```d class A { int a; B b; this(int a, int b) { this.a = a; this.b = new B(b); } } class B

lazy construction of an immutable object

2014-07-15 Thread Puming via Digitalmars-d-learn
class is companioned by a Builder class, with the same field of the immutable data class. 3. To create a data object, first create a Builder, then set the fields when ever you want. I want to emulate this process, but without needing to create two classes for one data class (protobuff does this

Re: Segfault in shared object when writeln

2014-06-03 Thread Harpo via Digitalmars-d-learn
Thanks! that was perfect. -Harpo

Re: Segfault in shared object when writeln

2014-06-03 Thread ed via Digitalmars-d-learn
On Wednesday, 4 June 2014 at 04:46:59 UTC, ed wrote: On Wednesday, 4 June 2014 at 03:49:25 UTC, Harpo wrote: Hello I am having the following problem. I am trying to turn a program I have written into a shared object. I have ran into some problems however. When I use writeln instead of printf

Re: Segfault in shared object when writeln

2014-06-03 Thread ed via Digitalmars-d-learn
On Wednesday, 4 June 2014 at 03:49:25 UTC, Harpo wrote: Hello I am having the following problem. I am trying to turn a program I have written into a shared object. I have ran into some problems however. When I use writeln instead of printf my program segfaults. I have edited the code to just

Segfault in shared object when writeln

2014-06-03 Thread Harpo via Digitalmars-d-learn
Hello I am having the following problem. I am trying to turn a program I have written into a shared object. I have ran into some problems however. When I use writeln instead of printf my program segfaults. I have edited the code to just the parts causing the problem. =main.d

Re: Can't call isDir on linux on const object

2014-05-19 Thread Spacen via Digitalmars-d-learn
On Monday, 19 May 2014 at 20:18:40 UTC, Adam D. Ruppe wrote: On Monday, 19 May 2014 at 20:11:45 UTC, Spacen wrote: The same code works on windows DMD 1.65. But on linux: It's because of caching. isDir on Linux calls a function with this comment: /++ This is to support la

Re: Can't call isDir on linux on const object

2014-05-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 19 May 2014 at 20:11:45 UTC, Spacen wrote: The same code works on windows DMD 1.65. But on linux: It's because of caching. isDir on Linux calls a function with this comment: /++ This is to support lazy evaluation, because doing stat's is expensive

Can't call isDir on linux on const object

2014-05-19 Thread Spacen via Digitalmars-d-learn
The same code works on windows DMD 1.65. But on linux: delold.d(54): Error: mutable method std.file.DirEntry.isDir is not callable using a const object [code] bool printFile(in DirEntry dirEntry, in Duration age, Options options) { immutable string type = dirEntry.isDir ? "dire

Re: Any equivalent to python's dir(object) in D?

2014-05-05 Thread bearophile via Digitalmars-d-learn
Chris Piker: Is there any way to get a list of the properties and functions provided by a module or class or generic variable in D at runtime? In D there are various traits to do that a compile-time. Like: http://dlang.org/traits.html#allMembers There are also the Phobos traits: http://dlang

Any equivalent to python's dir(object) in D?

2014-05-04 Thread Chris Piker via Digitalmars-d-learn
Is there any way to get a list of the properties and functions provided by a module or class or generic variable in D at runtime? I've grown quite accustomed to doing the following kinds of exploration in Python. With in the python interperter I can issue: a = some_barely_understood_functio

Re: Modify Object Pointer during Initialzation

2014-04-08 Thread Jeroen Bollen
On Tuesday, 8 April 2014 at 14:26:46 UTC, Adam D. Ruppe wrote: On Tuesday, 8 April 2014 at 14:23:02 UTC, Jeroen Bollen wrote: Is there a documentation page about the 'uniform function call syntax'? http://dlang.org/function.html#pseudo-member Oh beat me to it.

Re: Modify Object Pointer during Initialzation

2014-04-08 Thread Adam D. Ruppe
On Tuesday, 8 April 2014 at 14:23:02 UTC, Jeroen Bollen wrote: Is there a documentation page about the 'uniform function call syntax'? http://dlang.org/function.html#pseudo-member

Re: Modify Object Pointer during Initialzation

2014-04-08 Thread Jeroen Bollen
On Tuesday, 8 April 2014 at 14:23:02 UTC, Jeroen Bollen wrote: Is there a documentation page about the 'uniform function call syntax'? Never mind, I think I understand all there is to it.

Re: Modify Object Pointer during Initialzation

2014-04-08 Thread Jeroen Bollen
rence to each method would be a double pointer and wasted effort most the time; all most methods care about is where to get the object data, they don't need to know how the caller was getting to the object data. I don't see why this needs to be a new variable and cannot simply be '

Re: Modify Object Pointer during Initialzation

2014-04-08 Thread Adam D. Ruppe
most the time; all most methods care about is where to get the object data, they don't need to know how the caller was getting to the object data. I don't see why this needs to be a new variable and cannot simply be 'passed-by-reference'. You can get that with UFCS btw: c

Modify Object Pointer during Initialzation

2014-04-08 Thread Jeroen Bollen
This topic is somewhat related to this question I asked yesterday on StackOverflow: http://stackoverflow.com/q/22921395/2558778 Basically, why is this its own variable? Why doesn't D simply use the variable it was called with? https://gist.github.com/Binero/10128826 I don't see why this need

Re: mutable reference to const object

2014-03-06 Thread FreeSlave
Yes, in some cases C++ const does not provide const-guarantees, it's more like convention. For example, you can write this: class Class { public: Class() : ptr(new int()) {} ~Class() { delete ptr; } void setData(int data) const { *ptr = data; } private: int *ptr; };

Re: mutable reference to const object

2014-03-06 Thread Vadim Lopatin
On Thursday, 6 March 2014 at 17:47:34 UTC, bearophile wrote: There was a very long discussion on this. I think the short answer is to keep the syntax and semantics composed of a sufficiently low number of parts (in D you don't have syntax to tell apart objects from their references). Thank yo

Re: mutable reference to const object

2014-03-06 Thread Vadim Lopatin
On Thursday, 6 March 2014 at 15:54:13 UTC, FreeSlave wrote: You probably need Rebindable template from std.typecons. Thank you! Rebindable does exactly what I need. I'm just curious why there is no some syntax to describe the same. E.g. const(Foo) foo; // mutable ref to const o

Re: mutable reference to const object

2014-03-06 Thread bearophile
Vadim Lopatin: Const sub-tree is object itself and its data. Reference to object is outside of tree. Why references to const object should be const? There was a very long discussion on this. I think the short answer is to keep the syntax and semantics composed of a sufficiently low number

Re: mutable reference to const object

2014-03-06 Thread Vadim Lopatin
data they refer to: http://dlang.org/const3.html Bye, bearophile Const sub-tree is object itself and its data. Reference to object is outside of tree. Why references to const object should be const? Such references cannot be used to modify object anyway.

Re: mutable reference to const object

2014-03-06 Thread bearophile
Vadim Lopatin: In C++, following code works as I'm expecting: Different language, different (hopefully better) semantics. In D const and immutable are transitive, this means they make const/immutable the whole sub-tree of data they refer to: http://dlang.org/const3.html Bye, bearophile

Re: mutable reference to const object

2014-03-06 Thread FreeSlave
You probably need Rebindable template from std.typecons.

mutable reference to const object

2014-03-06 Thread Vadim Lopatin
Hello, Is there a possibility to define mutable reference to const object? I need variable which can be used to iterate through const objects. But it seems like const(Foo)p makes constant reference to constant object instead of mutable reference to const object. class Bar { } unittest

Re: Why does object creation give segmentation fault in DLL?

2014-02-22 Thread Tolga Cakiroglu
On Saturday, 22 February 2014 at 11:08:41 UTC, evilrat wrote: On Saturday, 22 February 2014 at 09:09:42 UTC, Tolga Cakiroglu wrote: I have written a DLL file in Linux (x86_64). It is as below: File: lib.dll = class A{} extern(C) void foo(){ Object obj = new Object

Re: Why does object creation give segmentation fault in DLL?

2014-02-22 Thread evilrat
On Saturday, 22 February 2014 at 09:09:42 UTC, Tolga Cakiroglu wrote: I have written a DLL file in Linux (x86_64). It is as below: File: lib.dll = class A{} extern(C) void foo(){ Object obj = new Object(); // test 1 A objA = new A(); // test 2

Why does object creation give segmentation fault in DLL?

2014-02-22 Thread Tolga Cakiroglu
I have written a DLL file in Linux (x86_64). It is as below: File: lib.dll = class A{} extern(C) void foo(){ Object obj = new Object(); // test 1 A objA = new A(); // test 2 char[] c = new char[ 1024 ]; // test 3 } Compilation code is below

Re: Adding object files to dub build?

2014-01-14 Thread Jesse Phillips
On Monday, 13 January 2014 at 20:48:11 UTC, Jesse Phillips wrote: I have a pre-built sqlite3 object file which I'd like to include as part of the linking for the final executable. I have been unable to find a way to do this with dub. I have attempted adding: "sourceFiles":

Adding object files to dub build?

2014-01-13 Thread Jesse Phillips
I have a pre-built sqlite3 object file which I'd like to include as part of the linking for the final executable. I have been unable to find a way to do this with dub. I have attempted adding: "sourceFiles": ["csqlite3.obj"], This doesn't work since it is a

Re: get address of object if opCast is overridden

2013-12-25 Thread Lionello Lunesu
On 12/2/12, 21:25, js.mdnq wrote: I'm not just comparing them but using them as a unique ID for the objects in an algorithm to prevent computing over the same object more than once. o.toHash() ?? (Which incidentally just casts the reference to a hash_t, exactly what you want to do.)

Re: Deep copy or clone data structure (or object ?)

2013-12-02 Thread Daniel Davidson
s of maps or an object with few structs inside ? I rolled my own generalized dup: https://github.com/patefacio/d-help/blob/master/d-help/opmix/dup.d I have since changed my philosophy to allow sharing more often than not - but it can be scary still so dup has advantages. Here is an example us

Re: Deep copy or clone data structure (or object ?)

2013-12-02 Thread bearophile
Dfr: I searched through various D documentation sources and did not found anything except 'std.copy', but it's only for slices. Is there such feature in standart library ? Or some easy way to clone for example map of slices of maps or an object with few structs inside ?

Deep copy or clone data structure (or object ?)

2013-12-02 Thread Dfr
Hi I searched through various D documentation sources and did not found anything except 'std.copy', but it's only for slices. Is there such feature in standart library ? Or some easy way to clone for example map of slices of maps or an object with few structs inside ?

Re: non-determinant object lifetime and memory management

2013-12-01 Thread Frustrated
parent object is done this wastes memory for no real reason except ease of use. Since many objects may contain a ptr to the array, what would be the best way to deal with deallocating them? I could wrap the array in a collection an use ARC but is there a better way? Is there something in

Re: non-determinant object lifetime and memory management

2013-11-30 Thread bioinfornatics
On Saturday, 30 November 2013 at 08:35:23 UTC, Frustrated wrote: I need to pass around some objects(specifically int[]) that may be used by several other objects at the same time. While I could clone these and free them when the parent object is done this wastes memory for no real reason

Re: non-determinant object lifetime and memory management

2013-11-30 Thread Frustrated
the parent object is done this wastes memory for no real reason except ease of use. Since many objects may contain a ptr to the array, what would be the best way to deal with deallocating them? I could wrap the array in a collection an use ARC but is there a better way? Is there something in

Re: non-determinant object lifetime and memory management

2013-11-30 Thread Rene Zwanenburg
On Saturday, 30 November 2013 at 08:35:23 UTC, Frustrated wrote: I need to pass around some objects(specifically int[]) that may be used by several other objects at the same time. While I could clone these and free them when the parent object is done this wastes memory for no real reason

Re: non-determinant object lifetime and memory management

2013-11-30 Thread bearophile
Frustrated: I need to pass around some objects(specifically int[]) that may be used by several other objects at the same time. While I could clone these and free them when the parent object is done this wastes memory for no real reason except ease of use. Since many objects may contain a

non-determinant object lifetime and memory management

2013-11-30 Thread Frustrated
I need to pass around some objects(specifically int[]) that may be used by several other objects at the same time. While I could clone these and free them when the parent object is done this wastes memory for no real reason except ease of use. Since many objects may contain a ptr to the array

Re: Object destruction versus finalization

2013-11-14 Thread Florian
Michael, thank you for these links. Regards, Florian.

Re: Object destruction versus finalization

2013-11-13 Thread Michael
Additional discussions http://forum.dlang.org/thread/jpl93e$1mns$1...@digitalmars.com and http://forum.dlang.org/thread/l3dj7b$2tvc$1...@digitalmars.com

Re: Object destruction versus finalization

2013-11-13 Thread Florian
Jonathan, Dicebot, thank you very much for your response. So you are confirming my conclusion, that finalizers/destructors in D work pretty much like in C++ and there is no way to do Java/C#/Managed C++-like finalization. For the records, since Dicebot asked: I am using DMD32 v2.063.2 on De

Re: Object destruction versus finalization

2013-11-12 Thread Dicebot
On Tuesday, 12 November 2013 at 22:40:26 UTC, Florian wrote: The example below prints the following output: ~Connection ~Session segmentation fault Same example prints this for me (no segfault): ~Session shutdown ~Connection 2.064.2 @ linux-64 What is your system / compiler? Outp

Re: Object destruction versus finalization

2013-11-12 Thread Dicebot
On Tuesday, 12 November 2013 at 23:18:11 UTC, Jonathan M Davis wrote: You can't do that in finalizer, because the GC can choose to free it before the finalizer even runs (this avoids issues with circular references). Ah, damn, have forgotten about it. Disregard previous post.

Re: Object destruction versus finalization

2013-11-12 Thread Jonathan M Davis
(and not on the GC heap aside from the fact that the instance of the class is itself on the GC heap) or which is not managed by the GC at all (e.g. it was malloced, or it was some other sort of system resource that the GC doesn't manage). If you want your Connection object to shutdown when

Re: Object destruction versus finalization

2013-11-12 Thread Florian
I understood very well, that the garbage collector is not guaranteed to run. However, it does not explain the segmentation fault in my example, does it?

Re: Object destruction versus finalization

2013-11-12 Thread Jonathan M Davis
On Tuesday, November 12, 2013 23:40:24 Florian wrote: > it would be possible to move the shutdown() sequence into the > destructor of the "Connection" class. Classes in D do not have destructors. Only structs to. ~this is a destructor in a struct, but it's a finalizer in a class. Finalizers are n

Re: Object destruction versus finalization

2013-11-12 Thread Florian
destructed have been destroyed themselfes (or at least have been brought into an invalid state). Therefore, these members cannot be accessed savely from inside the destructor. What made you think so? It must be other way around. Destructor is expected to release resources held by object, it is

Re: Object destruction versus finalization

2013-11-12 Thread Dicebot
brought into an invalid state). Therefore, these members cannot be accessed savely from inside the destructor. What made you think so? It must be other way around. Destructor is expected to release resources held by object, it is necessary that those resources are still valid at destructor call

Object destruction versus finalization

2013-11-12 Thread Florian
. Managed C++ offers both, C#-like finalizers and conventional C++ destructors, where the destructor is called ~className and the finalizer is called !className. Is their a best practice to mimikry this behaviour, i.e. to call a certain block of code when an object is being garbage collected, but

Re: Object construction and this

2013-11-10 Thread Alexandr Druzhinin
10.11.2013 23:22, Benjamin Thaut пишет: Am 10.11.2013 17:06, schrieb Alexandr Druzhinin: Because in D Classes are reference types. That means the code you wrote is equivalent to the following C++ source: class Foo { public: Foo(Object* o) { printf("%x\n", &this);

Re: Object construction and this

2013-11-10 Thread Benjamin Thaut
reference types. That means the code you wrote is equivalent to the following C++ source: class Foo { public: Foo(Object* o) { printf("%x\n", &this); // print a Foo** } } class Bar { public: Bar() { printf("%x\n", &this); // print a Bar** } } voi

Re: Object construction and this

2013-11-10 Thread anonymous
? The "bar" values are different, too. And they are, because you're printing the addresses of the references (variables), not the addresses of the objects. You can use cast(void*) to get the address of an object: class Bar { this() { writeln(c

Object construction and this

2013-11-10 Thread Alexandr Druzhinin
Could somebody explain why this http://dpaste.dzfl.pl/248262b9 return this: Foo: 7FBFD59A50 7FBFD59A80 Bar: 7FBFD59A58 7FBFD59A88 Why this value in ctor is different from this value out of ctor if ctor gets an argument?

Re: Is there any plans to allow rdmd to emit object files?

2013-10-01 Thread Gary Willoughby
On Tuesday, 1 October 2013 at 17:58:58 UTC, Jacob Carlborg wrote: On 2013-10-01 18:03, Gary Willoughby wrote: Are there any plans to allow rdmd to emit object files? I ask because i have a debugger id like to use that uses object files and my project is of sufficient complexity that rdmd is

Re: Is there any plans to allow rdmd to emit object files?

2013-10-01 Thread Jacob Carlborg
On 2013-10-01 18:03, Gary Willoughby wrote: Are there any plans to allow rdmd to emit object files? I ask because i have a debugger id like to use that uses object files and my project is of sufficient complexity that rdmd is needed to correctly compile the dependencies. What happens if you

Is there any plans to allow rdmd to emit object files?

2013-10-01 Thread Gary Willoughby
Are there any plans to allow rdmd to emit object files? I ask because i have a debugger id like to use that uses object files and my project is of sufficient complexity that rdmd is needed to correctly compile the dependencies.

Re: inout method is not callable using a const object

2013-09-06 Thread Jonathan Crapuchettes
On Fri, 06 Sep 2013 14:08:19 -0700, Ali Çehreli wrote: > I think it is the same issue then. > > On 09/06/2013 02:00 PM, Jonathan Crapuchettes wrote: > > >> > inout(DataT*) opIndex(const Address addr) inout { > > Unless Address is an alias of int, there is no matching opIndex overload >

Re: inout method is not callable using a const object

2013-09-06 Thread Ali Çehreli
On 09/06/2013 01:27 PM, Ali Çehreli wrote: the compiler should error about not finding a matching foo() overload instead of bringing the inout into the discussion. http://d.puremagic.com/issues/show_bug.cgi?id=10982 Ali

Re: inout method is not callable using a const object

2013-09-06 Thread Jonathan Crapuchettes
On Fri, 06 Sep 2013 13:27:20 -0700, Ali Çehreli wrote: > On 09/06/2013 01:14 PM, Jonathan Crapuchettes wrote: > > > Can someone help me understand how to correct this error? > > > > Error: inout method ...ValidSparseDataStore.opIndex is not callable > > using

Re: inout method is not callable using a const object

2013-09-06 Thread Ali Çehreli
I think it is the same issue then. On 09/06/2013 02:00 PM, Jonathan Crapuchettes wrote: >> > inout(DataT*) opIndex(const Address addr) inout { Unless Address is an alias of int, there is no matching opIndex overload for the following call: >auto dp = cStore[16057];//<-- ER

inout method is not callable using a const object

2013-09-06 Thread Jonathan Crapuchettes
Can someone help me understand how to correct this error? Error: inout method ...ValidSparseDataStore.opIndex is not callable using a const object The specific method is defined as: struct ValidSparseDataStore { inout(DataT*) opIndex(const Address addr) inout { if (auto node

Re: inout method is not callable using a const object

2013-09-06 Thread Ali Çehreli
On 09/06/2013 01:14 PM, Jonathan Crapuchettes wrote: > Can someone help me understand how to correct this error? > > Error: inout method ...ValidSparseDataStore.opIndex is not callable using > a const object That error is about opIndex but we don't see any code that makes

Re: Get class size of object

2013-08-12 Thread JS
On Monday, 12 August 2013 at 19:44:56 UTC, Jacob Carlborg wrote: On 2013-08-12 17:49, JS wrote: Sorry but this doesn't work. b is a B, not an A. try I a = new A; I b = new B; Right, forgot about the interface. NP, happens to all of us. Simen's method of casting to object s

Re: Get class size of object

2013-08-12 Thread Jacob Carlborg
On 2013-08-12 17:49, JS wrote: Sorry but this doesn't work. b is a B, not an A. try I a = new A; I b = new B; Right, forgot about the interface. -- /Jacob Carlborg

Re: Get class size of object

2013-08-12 Thread JS
On Monday, 12 August 2013 at 11:34:25 UTC, Jacob Carlborg wrote: On 2013-08-11 21:08, Simen Kjaeraas wrote: If you're looking for a no-overhead solution, then this might not be good enough. I'm surprised that a virtual function call is fine, though. How about this: interface I { size_t

Re: Get class size of object

2013-08-12 Thread Jacob Carlborg
On 2013-08-11 21:08, Simen Kjaeraas wrote: If you're looking for a no-overhead solution, then this might not be good enough. I'm surprised that a virtual function call is fine, though. How about this: interface I { size_t size (this T) () { return __traits(classInstanceSize, T

Re: Get class size of object

2013-08-12 Thread John Colvin
On Sunday, 11 August 2013 at 18:29:15 UTC, JS wrote: On Sunday, 11 August 2013 at 18:18:22 UTC, Dicebot wrote: On Sunday, 11 August 2013 at 17:03:04 UTC, JS wrote: This is essentially what I'm doing BUT I am trying to avoid having to repeat the exact same crap in every class because it is time

Re: Get class size of object

2013-08-11 Thread JS
Object - it might also be a C++ class, or a COM object, or maybe even a slice into another vtbl if an Object implements multiple interfaces (not completely sure about the latter, I'd have to read some source, but it seems logical to me). Possibly. Since I program to interfaces,

Re: Get class size of object

2013-08-11 Thread Adam D. Ruppe
On Sunday, 11 August 2013 at 19:58:26 UTC, Adam D. Ruppe wrote: Oh, I see it now. I think typeid(interface) gives a different set of info. Thinking about it a bit more, this makes sense because an interface is not necessarily an Object - it might also be a C++ class, or a COM object, or

Re: Get class size of object

2013-08-11 Thread Adam D. Ruppe
writeln(typeid(cast(Object)(f)).init.length); Just casting the interface to Object before fetching the info.

<    5   6   7   8   9   10   11   12   13   14   >