Re: Memory management

2020-10-02 Thread Dukc via Digitalmars-d-learn
On Tuesday, 29 September 2020 at 10:57:07 UTC, novice3 wrote: Naive newbie question: Can we have (in theory) in D lang memory management like V lang? I don't know V so can't be sure, but doing it the same way as in the examples sounds possible. The first two calls are easy

Re: Memory management

2020-09-29 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Tuesday, 29 September 2020 at 16:03:39 UTC, IGotD- wrote: That little simple example shows that you don't necessarily need to know things in advance in order to have static lifetimes. However, there are examples where there is no possibility for the compiler to infer when the object goes out

Re: Memory management

2020-09-29 Thread bachmeier via Digitalmars-d-learn
On Tuesday, 29 September 2020 at 10:57:07 UTC, novice3 wrote: Naive newbie question: Can we have (in theory) in D lang memory management like V lang? Quote: https://github.com/vlang/v/blob/master/doc/docs.md#memory-management "V doesn't use garbage collection or reference cou

Re: Memory management

2020-09-29 Thread IGotD- via Digitalmars-d-learn
On Tuesday, 29 September 2020 at 15:47:09 UTC, Ali Çehreli wrote: I am not a language expert but I can't imagine how the compiler knows whether an event will happen at runtime. Imagine a server program allocates memory for a client. Let's say, that memory will be deallocated when the client l

Re: Memory management

2020-09-29 Thread Ali Çehreli via Digitalmars-d-learn
On 9/29/20 3:57 AM, novice3 wrote:> Naive newbie question: > > Can we have (in theory) in D lang memory management like V lang? > > Quote: > https://github.com/vlang/v/blob/master/doc/docs.md#memory-management > > "V doesn't use garbage collection or referen

Memory management

2020-09-29 Thread novice3 via Digitalmars-d-learn
Naive newbie question: Can we have (in theory) in D lang memory management like V lang? Quote: https://github.com/vlang/v/blob/master/doc/docs.md#memory-management "V doesn't use garbage collection or reference counting. The compiler cleans everything up during compilation.

Re: Just another question about memory management in d from a newbie

2019-06-17 Thread Thomas via Digitalmars-d-learn
On Monday, 17 June 2019 at 20:26:28 UTC, H. S. Teoh wrote: On Mon, Jun 17, 2019 at 07:53:52PM +, Thomas via Digitalmars-d-learn wrote: [...] [...] If x were a heap-allocated object, then your concerns would be true: it would be allocated once every iteration (and also add to the garbage

Re: Just another question about memory management in d from a newbie

2019-06-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 17, 2019 at 07:53:52PM +, Thomas via Digitalmars-d-learn wrote: [...] > int main() > { > foreach(i;0 .. 1) > { > int x; > // do something with x > } > return 0; > } > > Do I understand it right that the variable x will be created 1 > times an

Re: Just another question about memory management in d from a newbie

2019-06-17 Thread Thomas via Digitalmars-d-learn
First, thank you for your fast reply! On Monday, 17 June 2019 at 20:00:34 UTC, Adam D. Ruppe wrote: No, the compiler will generate code to reuse the same thing each loop. Does this code also work on complex types like structs ?

Re: Just another question about memory management in d from a newbie

2019-06-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 17 June 2019 at 19:53:52 UTC, Thomas wrote: Do I understand it right that the variable x will be created 1 times and destroyed at the end of the scope in each loop ? Or will it be 1 overwritten by creation ? No, the compiler will generate code to reuse the same thing each l

Just another question about memory management in d from a newbie

2019-06-17 Thread Thomas via Digitalmars-d-learn
Hello! First my background: C++ and Java ages ago. Since then only PLSQL. Now learning D just for fun and personal education on time to time and very pleased about it :-) Now I have to ask a question here, because I could not find a corresponding answer for it. Or I am unable to find it :-)

Re: Memory management by interfacing C/C++

2019-04-29 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Monday, 29 April 2019 at 14:38:54 UTC, 9il wrote: On Saturday, 27 April 2019 at 22:25:58 UTC, Ferhat Kurtulmuş wrote: [...] Hello Ferhat, You can use RCArray!T or Slice!(RCI!T) [1, 2] as common thread safe @nogc types for D and C++ code. See also integration C++ example [3] and C++ heade

Re: Memory management by interfacing C/C++

2019-04-29 Thread 9il via Digitalmars-d-learn
On Saturday, 27 April 2019 at 22:25:58 UTC, Ferhat Kurtulmuş wrote: Hi, I am wrapping some C++ code for my personal project (opencvd), and I am creating so many array pointers at cpp side and containing them in structs. I want to learn if I am leaking memory like crazy, although I am not faci

Re: Memory management by interfacing C/C++

2019-04-29 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Monday, 29 April 2019 at 00:53:34 UTC, Paul Backus wrote: On Sunday, 28 April 2019 at 23:10:24 UTC, Ferhat Kurtulmuş wrote: You are right. I am rewriting the things using mallocs, and will use core.stdc.stdlib.free on d side. I am not sure if I can use core.stdc.stdlib.free to destroy arrays

Re: Memory management by interfacing C/C++

2019-04-28 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 28 April 2019 at 23:10:24 UTC, Ferhat Kurtulmuş wrote: You are right. I am rewriting the things using mallocs, and will use core.stdc.stdlib.free on d side. I am not sure if I can use core.stdc.stdlib.free to destroy arrays allocated with new op. core.stdc.stdlib.free is (as the na

Re: Memory management by interfacing C/C++

2019-04-28 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Sunday, 28 April 2019 at 03:54:17 UTC, Paul Backus wrote: On Saturday, 27 April 2019 at 22:25:58 UTC, Ferhat Kurtulmuş wrote: Hi, I am wrapping some C++ code for my personal project (opencvd), and I am creating so many array pointers at cpp side and containing them in structs. I want to le

Re: Memory management by interfacing C/C++

2019-04-27 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 27 April 2019 at 22:25:58 UTC, Ferhat Kurtulmuş wrote: Hi, I am wrapping some C++ code for my personal project (opencvd), and I am creating so many array pointers at cpp side and containing them in structs. I want to learn if I am leaking memory like crazy, although I am not faci

Memory management by interfacing C/C++

2019-04-27 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
Hi, I am wrapping some C++ code for my personal project (opencvd), and I am creating so many array pointers at cpp side and containing them in structs. I want to learn if I am leaking memory like crazy, although I am not facing crashes so far. Is GC of D handling things for me? Here is an exa

Re: Block statements and memory management

2019-04-05 Thread Murilo via Digitalmars-d-learn
On Saturday, 16 March 2019 at 15:53:26 UTC, Johan Engelen wrote: On Saturday, 16 March 2019 at 03:47:43 UTC, Murilo wrote: Does anyone know if when I create a variable inside a scope as in {int a = 10;} it disappears complete from the memory when the scope finishes? Or does it remain in some p

Re: Block statements and memory management

2019-03-16 Thread Johan Engelen via Digitalmars-d-learn
On Saturday, 16 March 2019 at 03:47:43 UTC, Murilo wrote: Does anyone know if when I create a variable inside a scope as in {int a = 10;} it disappears complete from the memory when the scope finishes? Or does it remain in some part of the memory? I am thinking of using scopes to make optimize

Re: Block statements and memory management

2019-03-16 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Mar 16, 2019 at 01:21:02PM +0100, spir via Digitalmars-d-learn wrote: > On 16/03/2019 11:19, Dennis via Digitalmars-d-learn wrote: [...] > > In any case, for better memory efficiency I'd consider looking at > > reducing dynamic allocations such as new or malloc. Memory on the > > stack is b

Re: Block statements and memory management

2019-03-16 Thread spir via Digitalmars-d-learn
On 16/03/2019 11:19, Dennis via Digitalmars-d-learn wrote: On Saturday, 16 March 2019 at 03:47:43 UTC, Murilo wrote: Does anyone know if when I create a variable inside a scope as in {int a = 10;} it disappears complete from the memory when the scope finishes? Or does it remain in some part of

Re: Block statements and memory management

2019-03-16 Thread Dennis via Digitalmars-d-learn
On Saturday, 16 March 2019 at 03:47:43 UTC, Murilo wrote: Does anyone know if when I create a variable inside a scope as in {int a = 10;} it disappears complete from the memory when the scope finishes? Or does it remain in some part of the memory? I am thinking of using scopes to make optimize

Re: Block statements and memory management

2019-03-15 Thread Meta via Digitalmars-d-learn
On Saturday, 16 March 2019 at 03:47:43 UTC, Murilo wrote: Does anyone know if when I create a variable inside a scope as in {int a = 10;} it disappears complete from the memory when the scope finishes? Or does it remain in some part of the memory? I am thinking of using scopes to make optimize

Re: Block statements and memory management

2019-03-15 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 16 March 2019 at 03:47:43 UTC, Murilo wrote: Does anyone know if when I create a variable inside a scope as in {int a = 10;} it disappears complete from the memory when the scope finishes? Or does it remain in some part of the memory? I am thinking of using scopes to make optimize

Block statements and memory management

2019-03-15 Thread Murilo via Digitalmars-d-learn
Does anyone know if when I create a variable inside a scope as in {int a = 10;} it disappears complete from the memory when the scope finishes? Or does it remain in some part of the memory? I am thinking of using scopes to make optimized programs that consume less memory.

Re: Region-based memory management and GC?

2017-09-30 Thread Jon Degenhardt via Digitalmars-d-learn
On Saturday, 30 September 2017 at 07:41:21 UTC, Igor wrote: On Friday, 29 September 2017 at 22:13:01 UTC, Jon Degenhardt wrote: Have there been any investigations into using region-based memory management (aka memory arenas) in D, possibly in conjunction with GC allocated memory? Sounds like

Re: Region-based memory management and GC?

2017-09-30 Thread Igor via Digitalmars-d-learn
On Friday, 29 September 2017 at 22:13:01 UTC, Jon Degenhardt wrote: Have there been any investigations into using region-based memory management (aka memory arenas) in D, possibly in conjunction with GC allocated memory? This would be a very speculative idea, but it'd be interesting to kn

Region-based memory management and GC?

2017-09-29 Thread Jon Degenhardt via Digitalmars-d-learn
Have there been any investigations into using region-based memory management (aka memory arenas) in D, possibly in conjunction with GC allocated memory? This would be a very speculative idea, but it'd be interesting to know if there have been looks at this area. My own interest is re

Re: Best memory management D idioms

2017-03-08 Thread Moritz Maxeiner via Digitalmars-d-learn
On Wednesday, 8 March 2017 at 06:42:40 UTC, ag0aep6g wrote: [...] Yes and yes. GCAllocator.allocate calls core.memory.GC.malloc with does pretty much the same thing as the builtin `new`. Nitpicking: `new` is typed (i.e. allocation+construction), `malloc` and `allocate` are not (only allocati

Re: Best memory management D idioms

2017-03-07 Thread ag0aep6g via Digitalmars-d-learn
On 03/08/2017 02:15 AM, XavierAP wrote: I see the default allocator is the same GC heap used by 'new'. Just for my learning curiosity, does this mean that if I theAllocator.make() something and then forget to dispose() it, it will be garbage collected the same once no longer referenced? And so ar

Re: Best memory management D idioms

2017-03-07 Thread XavierAP via Digitalmars-d-learn
ental.allocator; it looks really powerful and general, more than I need. I see the potential but I don't really have the knowledge to tweak memory management, and the details of the "building blocks" are well beyond me. But even if I don't go there, I guess it's a good

Re: Best memory management D idioms

2017-03-07 Thread Eugene Wissner via Digitalmars-d-learn
On Tuesday, 7 March 2017 at 20:15:37 UTC, XavierAP wrote: On Tuesday, 7 March 2017 at 18:21:43 UTC, Eugene Wissner wrote: To avoid this from the beginning, it may be better to use allocators. You can use "make" and "dispose" from std.experimental.allocator the same way as New/Delete. Thanks!

Re: Best memory management D idioms

2017-03-07 Thread XavierAP via Digitalmars-d-learn
On Tuesday, 7 March 2017 at 18:21:43 UTC, Eugene Wissner wrote: To avoid this from the beginning, it may be better to use allocators. You can use "make" and "dispose" from std.experimental.allocator the same way as New/Delete. Thanks! looking into it. Does std.experimental.allocator have a le

Re: Best memory management D idioms

2017-03-07 Thread Eugene Wissner via Digitalmars-d-learn
On Tuesday, 7 March 2017 at 17:37:43 UTC, XavierAP wrote: On Tuesday, 7 March 2017 at 16:51:23 UTC, Kagamin wrote: There's nothing like that of C++. Don't you think New/Delete from dlib.core.memory fills the bill? for C++ style manual dynamic memory management? It looks quite

Re: Best memory management D idioms

2017-03-07 Thread XavierAP via Digitalmars-d-learn
On Tuesday, 7 March 2017 at 16:51:23 UTC, Kagamin wrote: There's nothing like that of C++. Don't you think New/Delete from dlib.core.memory fills the bill? for C++ style manual dynamic memory management? It looks quite nice to me, being no more than a simple malloc wrapper with c

Re: Best memory management D idioms

2017-03-07 Thread Kagamin via Digitalmars-d-learn
On Sunday, 5 March 2017 at 20:54:06 UTC, XavierAP wrote: What I want to learn (not debate) is the currently available types, idioms etc. whenever one wants deterministic memory management. There's nothing like that of C++. Currently you have Unique, RefCounted, scoped and individual p

Re: Best memory management D idioms

2017-03-06 Thread XavierAP via Digitalmars-d-learn
On Monday, 6 March 2017 at 08:26:53 UTC, Eugene Wissner wrote: The memory management in D is becoming a mess. I am aware this is a hot topic, hence the opening joke. But I just want to learn what toolboxes are currently available, not really discuss how adequate they are, or how often GC is

Re: Best memory management D idioms

2017-03-06 Thread Eugene Wissner via Digitalmars-d-learn
On Sunday, 5 March 2017 at 20:54:06 UTC, XavierAP wrote: I was going to name this thread "SEX!!" but then I thought "best memory management" would get me more reads ;) Anyway now that I have your attention... What I want to learn (not debate) is the currently availabl

Best memory management D idioms

2017-03-05 Thread XavierAP via Digitalmars-d-learn
I was going to name this thread "SEX!!" but then I thought "best memory management" would get me more reads ;) Anyway now that I have your attention... What I want to learn (not debate) is the currently available types, idioms etc. whenever one wants deterministic memory m

Re: Classes and Structs, Memory management questions

2016-09-02 Thread ikod via Digitalmars-d-learn
bably a good idea. Having a self managed reference to the heap can be good too if manual memory management is wanted. Or of course let the GC manage it ( i love it for prototyping code and also as a D beginner it is beneficial that i just dont need to care about memory management). Could som

Re: Classes and Structs, Memory management questions

2016-09-02 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 2 September 2016 at 08:43:45 UTC, dom wrote: from what i got Classes are always reference types and structs are value types in D. i am wondering why that is. for me the main difference between classes and structs is not how they are allocated, but that one has inhertiance, and the ot

Re: Classes and Structs, Memory management questions

2016-09-02 Thread Mike Parker via Digitalmars-d-learn
On Friday, 2 September 2016 at 08:43:45 UTC, dom wrote: from what i got Classes are always reference types and structs are value types in D. i am wondering why that is. for me the main difference between classes and structs is not how they are allocated, but that one has inhertiance, and the ot

Re: Classes and Structs, Memory management questions

2016-09-02 Thread dom via Digitalmars-d-learn
On Friday, 2 September 2016 at 08:59:38 UTC, Andrea Fontana wrote: On Friday, 2 September 2016 at 08:54:33 UTC, dom wrote: i haven't read it fully yet, but i think this DIP contains some or all of my concerns https://github.com/dlang/DIPs/blob/master/DIPs/DIP1000.md Check this: https://dlang.

Re: Classes and Structs, Memory management questions

2016-09-02 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 2 September 2016 at 08:54:33 UTC, dom wrote: i haven't read it fully yet, but i think this DIP contains some or all of my concerns https://github.com/dlang/DIPs/blob/master/DIPs/DIP1000.md Check this: https://dlang.org/phobos/std_experimental_allocator.html

Re: Classes and Structs, Memory management questions

2016-09-02 Thread dom via Digitalmars-d-learn
i haven't read it fully yet, but i think this DIP contains some or all of my concerns https://github.com/dlang/DIPs/blob/master/DIPs/DIP1000.md

Classes and Structs, Memory management questions

2016-09-02 Thread dom via Digitalmars-d-learn
d idea. Having a self managed reference to the heap can be good too if manual memory management is wanted. Or of course let the GC manage it ( i love it for prototyping code and also as a D beginner it is beneficial that i just dont need to care about memory management). Could somebody explai

Re: Preferred method of creating objects, structs, and arrays with deterministic memory management

2016-06-01 Thread Guillaume Piolat via Digitalmars-d-learn
On Wednesday, 1 June 2016 at 08:53:01 UTC, Rene Zwanenburg wrote: I was wondering: what's the preferred method for deterministic memory management? You can annotate your functions as @nogc. The compiler will disallow any potential GC use, including calling other functions that are not

Re: Preferred method of creating objects, structs, and arrays with deterministic memory management

2016-06-01 Thread Rene Zwanenburg via Digitalmars-d-learn
I was wondering: what's the preferred method for deterministic memory management? You may be interested in RefCounted. It only works for structs, not classes, but it's still useful. - Classes/Structs have constructors and destructors. I am unconfident with my knowledge as to how

Re: Preferred method of creating objects, structs, and arrays with deterministic memory management

2016-06-01 Thread Seb via Digitalmars-d-learn
On Wednesday, 1 June 2016 at 07:59:50 UTC, Anthony Monterrosa wrote: I've recently been trying to convince a friend of mine that D has at least the functionality of C++, and have been learning the language over C++ for a few months. Memory management is pretty important to him, and a su

Re: Preferred method of creating objects, structs, and arrays with deterministic memory management

2016-06-01 Thread rikki cattermole via Digitalmars-d-learn
On 01/06/2016 7:59 PM, Anthony Monterrosa wrote: I've recently been trying to convince a friend of mine that D has at least the functionality of C++, and have been learning the language over C++ for a few months. Memory management is pretty important to him, and a subject I'm honest

Preferred method of creating objects, structs, and arrays with deterministic memory management

2016-06-01 Thread Anthony Monterrosa via Digitalmars-d-learn
I've recently been trying to convince a friend of mine that D has at least the functionality of C++, and have been learning the language over C++ for a few months. Memory management is pretty important to him, and a subject I'm honestly curious about as well. I was wondering:

Re: Example of code with manual memory management

2016-02-19 Thread Kagamin via Digitalmars-d-learn
https://dlang.org/phobos/std_container.html and corresponding code in phobos. Though recently allocators were introduced and containers are going to be written with support for allocators.

Example of code with manual memory management

2016-02-19 Thread Dibyendu Majumdar via Digitalmars-d-learn
Hi, I am looking for example of types where memory management is manual, and the type supports operator overloading, etc. Grateful if someone could point me to sample example code. Thanks and Regards Dibyendu

Re: D Beginner Trying Manual Memory Management

2015-01-14 Thread Laeeth Isharc via Digitalmars-d-learn
I don't think you've read h5py source in enough detail :) You're right - I haven't done more than browsed it. It's based HEAVILY on duck typing. There is a question here about what to do in D. On the one hand, the flexibility of being able to open a foreign HDF5 file where you don't know

Re: D Beginner Trying Manual Memory Management

2015-01-14 Thread aldanor via Digitalmars-d-learn
On Wednesday, 14 January 2015 at 16:27:17 UTC, Laeeth Isharc wrote: struct File { Location _location; alias _location this; ... } // group.d public import commonfg; struct File { Location _location; alias _location this; ... } // commonfg.d { ... } enum isContainer(T) = is(T: File) || is(T :

Re: D Beginner Trying Manual Memory Management

2015-01-14 Thread Laeeth Isharc via Digitalmars-d-learn
struct File { Location _location; alias _location this; ... } // group.d public import commonfg; struct File { Location _location; alias _location this; ... } // commonfg.d { ... } enum isContainer(T) = is(T: File) || is(T : Group); auto method1(T)(T obj, args) if (isContainer!T) { ... } auto

Re: D Beginner Trying Manual Memory Management

2015-01-14 Thread aldanor via Digitalmars-d-learn
On Wednesday, 14 January 2015 at 14:54:09 UTC, Laeeth Isharc wrote: In the hierarchy example above (c++ hdf hierarchy link), by using UFCS to implement the shared methods (which are achieved by multiple inheritance in the c++ counterpart) did you mean something like this? // id.d struct ID

Re: D Beginner Trying Manual Memory Management

2015-01-14 Thread Laeeth Isharc via Digitalmars-d-learn
In the hierarchy example above (c++ hdf hierarchy link), by using UFCS to implement the shared methods (which are achieved by multiple inheritance in the c++ counterpart) did you mean something like this? // id.d struct ID { int id; ... } // location.d struct Location { ID _id; alias _id t

Re: D Beginner Trying Manual Memory Management

2015-01-13 Thread ketmar via Digitalmars-d-learn
On Tue, 13 Jan 2015 18:35:15 + aldanor via Digitalmars-d-learn wrote: > I guess two of my gripes with UFCS is (a) you really have to use > public imports in the modules where the target types are defined > so you bring all the symbols in whether you want it or not (b) > you lose access to

Re: D Beginner Trying Manual Memory Management

2015-01-13 Thread aldanor via Digitalmars-d-learn
On Tuesday, 13 January 2015 at 17:08:38 UTC, Laeeth Isharc wrote: >> I see, thanks! :) I've started liking structs more and >> more recently as well and been pondering on how to convert >> a class-based code that looks like this (only the base >> class has any data): > it's hard to tell by brie

Re: D Beginner Trying Manual Memory Management

2015-01-13 Thread ketmar via Digitalmars-d-learn
On Tue, 13 Jan 2015 17:08:37 + Laeeth Isharc via Digitalmars-d-learn wrote: > I just finished reading aldanor's blog, so I know he is slightly > allergic to naked functions and prefers classes ;) that's due to absense of modules in C/C++. and namespaces aren't of big help here too. and, of c

Re: D Beginner Trying Manual Memory Management

2015-01-13 Thread Laeeth Isharc via Digitalmars-d-learn
>> I see, thanks! :) I've started liking structs more and more >> recently as well and been pondering on how to convert a >> class-based code that looks like this (only the base class >> has any data): > it's hard to tell by brief description. but having multiple > inheritance > immediately rin

Re: D Beginner Trying Manual Memory Management

2015-01-13 Thread ketmar via Digitalmars-d-learn
On Tue, 13 Jan 2015 16:08:15 + aldanor via Digitalmars-d-learn wrote: > On Tuesday, 13 January 2015 at 08:33:57 UTC, ketmar via > Digitalmars-d-learn wrote: > > On Mon, 12 Jan 2015 22:07:13 + > > aldanor via Digitalmars-d-learn > > > > wrote: > > > >> I see, thanks! :) I've started lik

Re: D Beginner Trying Manual Memory Management

2015-01-13 Thread aldanor via Digitalmars-d-learn
On Tuesday, 13 January 2015 at 08:33:57 UTC, ketmar via Digitalmars-d-learn wrote: On Mon, 12 Jan 2015 22:07:13 + aldanor via Digitalmars-d-learn wrote: I see, thanks! :) I've started liking structs more and more recently as well and been pondering on how to convert a class-based code t

Re: D Beginner Trying Manual Memory Management

2015-01-13 Thread ketmar via Digitalmars-d-learn
On Mon, 12 Jan 2015 22:07:13 + aldanor via Digitalmars-d-learn wrote: > I see, thanks! :) I've started liking structs more and more > recently as well and been pondering on how to convert a > class-based code that looks like this (only the base class has > any data): p.s. can't you convert

Re: D Beginner Trying Manual Memory Management

2015-01-13 Thread ketmar via Digitalmars-d-learn
On Mon, 12 Jan 2015 22:07:13 + aldanor via Digitalmars-d-learn wrote: > I see, thanks! :) I've started liking structs more and more > recently as well and been pondering on how to convert a > class-based code that looks like this (only the base class has > any data): it's hard to tell by b

Re: D Beginner Trying Manual Memory Management

2015-01-13 Thread ketmar via Digitalmars-d-learn
On Mon, 12 Jan 2015 23:06:16 + jmh530 via Digitalmars-d-learn wrote: > I had seen some stuff on alias thing, but I hadn't bothered to > try to understand it until now. If I'm understanding the first > example http://dlang.org/class.html#AliasThis";>here, > alias this let's you refer to x in s

Re: D Beginner Trying Manual Memory Management

2015-01-12 Thread jmh530 via Digitalmars-d-learn
I had seen some stuff on alias thing, but I hadn't bothered to try to understand it until now. If I'm understanding the first example http://dlang.org/class.html#AliasThis";>here, alias this let's you refer to x in s by writing either s.x (as normally) or just s. That didn't seem that interesting,

Re: D Beginner Trying Manual Memory Management

2015-01-12 Thread Mike via Digitalmars-d-learn
I am concerned about performance of D vs. C++, so I wanted to learn a little bit more about manual memory management, in case I might ever need it (not for any particular application). There is a good article on the D Wiki that covers this topic with several different patterns and working exa

Re: D Beginner Trying Manual Memory Management

2015-01-12 Thread aldanor via Digitalmars-d-learn
On Monday, 12 January 2015 at 21:54:51 UTC, ketmar via Digitalmars-d-learn wrote: On Mon, 12 Jan 2015 21:37:27 + aldanor via Digitalmars-d-learn wrote: On Monday, 12 January 2015 at 20:30:45 UTC, ketmar via Digitalmars-d-learn wrote: > it even has `RefCounted!`, but it doesn't play well

Re: D Beginner Trying Manual Memory Management

2015-01-12 Thread ketmar via Digitalmars-d-learn
On Mon, 12 Jan 2015 21:37:27 + aldanor via Digitalmars-d-learn wrote: > On Monday, 12 January 2015 at 20:30:45 UTC, ketmar via > Digitalmars-d-learn wrote: > > it even has `RefCounted!`, but it doesn't play well with > > classes yet > > (AFAIR). > I wonder if it's possible to somehow make a

Re: D Beginner Trying Manual Memory Management

2015-01-12 Thread aldanor via Digitalmars-d-learn
On Monday, 12 January 2015 at 20:30:45 UTC, ketmar via Digitalmars-d-learn wrote: it even has `RefCounted!`, but it doesn't play well with classes yet (AFAIR). I wonder if it's possible to somehow make a version of refcounted that would work with classes (even if limited/restricted in some cer

Re: D Beginner Trying Manual Memory Management

2015-01-12 Thread ketmar via Digitalmars-d-learn
On Mon, 12 Jan 2015 20:14:19 + jmh530 via Digitalmars-d-learn wrote: > Thanks for the reply, I wasn't familiar with scoped. I was aware > that structs are on the stack and classes are on the heap in D, > but I didn't know it was possible to put a class on the stack. > Might be interesting

Re: D Beginner Trying Manual Memory Management

2015-01-12 Thread jmh530 via Digitalmars-d-learn
Thanks for the reply, I wasn't familiar with scoped. I was aware that structs are on the stack and classes are on the heap in D, but I didn't know it was possible to put a class on the stack. Might be interesting to see how this is implemented. After looking up some more C++, I think what I wa

Re: D Beginner Trying Manual Memory Management

2015-01-12 Thread ketmar via Digitalmars-d-learn
On Mon, 12 Jan 2015 19:29:53 + jmh530 via Digitalmars-d-learn wrote: the proper answer is too long to write (it will be more an article that a forum answer ;-), so i'll just give you some directions: import std.typecons; { auto b = scoped!B(); // `auto` is important here! ...

D Beginner Trying Manual Memory Management

2015-01-12 Thread jmh530 via Digitalmars-d-learn
ed to learn a little bit more about manual memory management, in case I might ever need it (not for any particular application). The D Language book Section 6.3.4-5 covers the topic. I basically copied below and made some small changes. import core.stdc.stdlib; import std.stdio; class B

Re: custom memory management

2014-02-28 Thread Namespace
On Friday, 28 February 2014 at 14:47:31 UTC, Dicebot wrote: On Friday, 28 February 2014 at 14:08:11 UTC, Namespace wrote: No, currently it is not deprecated. It is suggested to be deprecated. :P And destroy doesn't finalize the data. :/ See: http://forum.dlang.org/thread/bug-1225...@https.d.pur

Re: custom memory management

2014-02-28 Thread Dicebot
On Friday, 28 February 2014 at 14:08:11 UTC, Namespace wrote: No, currently it is not deprecated. It is suggested to be deprecated. :P And destroy doesn't finalize the data. :/ See: http://forum.dlang.org/thread/bug-1225...@https.d.puremagic.com%2Fissues%2F and http://forum.dlang.org/thread/bu

Re: custom memory management

2014-02-28 Thread Namespace
On Friday, 28 February 2014 at 13:38:59 UTC, Dicebot wrote: On Friday, 28 February 2014 at 13:32:33 UTC, Namespace wrote: I will vote, too. It's somewhat strange: Since it works with delete it should also work with the current GC, or? Someone should figure out why and how delete works this way.

Re: custom memory management

2014-02-28 Thread Namespace
On Friday, 28 February 2014 at 13:16:40 UTC, Dicebot wrote: On Friday, 28 February 2014 at 13:06:05 UTC, Namespace wrote: What can still take a long time. It annoys me very much that with arrays I can not rely on that the struct DTors are called. Yep, this bug has immediately got my vote :) It

Re: custom memory management

2014-02-28 Thread Dicebot
On Friday, 28 February 2014 at 13:32:33 UTC, Namespace wrote: I will vote, too. It's somewhat strange: Since it works with delete it should also work with the current GC, or? Someone should figure out why and how delete works this way. :) Well, delete is deprecated so it can do any kind of arc

Re: custom memory management

2014-02-28 Thread Namespace
On Friday, 28 February 2014 at 12:54:32 UTC, Dicebot wrote: On Friday, 28 February 2014 at 12:36:48 UTC, Simon Bürger wrote: If you are right that would mean that the current dmd/runtime does not follow the spec. Curious. The current implementation is not aware of strcut-destructors on the heap

Re: custom memory management

2014-02-28 Thread Dicebot
On Friday, 28 February 2014 at 13:06:05 UTC, Namespace wrote: What can still take a long time. It annoys me very much that with arrays I can not rely on that the struct DTors are called. Yep, this bug has immediately got my vote :) It does require someone knowledgable of GC to fix in forseeabl

Re: custom memory management

2014-02-28 Thread Dicebot
On Friday, 28 February 2014 at 12:36:48 UTC, Simon Bürger wrote: If you are right that would mean that the current dmd/runtime does not follow the spec. Curious. The current implementation is not aware of strcut-destructors on the heap, i.e. the GC.BlkAttr.FINALIZE flag is not set for structs (

Re: custom memory management

2014-02-28 Thread Simon Bürger
On Friday, 28 February 2014 at 10:40:17 UTC, Dicebot wrote: On Thursday, 27 February 2014 at 21:46:17 UTC, Simon Bürger wrote: Sadly, this is incorrect as well. Because if such an object is collected by the gc, but the gc decides not to run the destructor, the buffer will never be free'd. I t

Re: custom memory management

2014-02-28 Thread Dicebot
On Thursday, 27 February 2014 at 21:46:17 UTC, Simon Bürger wrote: Sadly, this is incorrect as well. Because if such an object is collected by the gc, but the gc decides not to run the destructor, the buffer will never be free'd. I think you misiterpret the spec. If object is collected, destr

Re: custom memory management

2014-02-28 Thread Bienlein
I asked something similar some days ago. Maybe this provides some information tat is helpful to you: http://forum.dlang.org/thread/mekdjoyejtfpafpcd...@forum.dlang.org

Re: custom memory management

2014-02-27 Thread Steven Schveighoffer
On Thu, 27 Feb 2014 16:46:15 -0500, Simon Bürger wrote: I know the suggested way in D is to not deallocate the buffer at all, but rely on the gc to collect it eventually. But it still puzzles me that it seems to be impossible to do. Anybody have an idea how I could make it work? Unfort

Re: custom memory management

2014-02-27 Thread Simon Bürger
On Thursday, 27 February 2014 at 22:15:41 UTC, Steven Schveighoffer wrote: On Thu, 27 Feb 2014 16:46:15 -0500, Simon Bürger [...] More and more, I think a thread-local flag of "I'm in the GC collection cycle" would be hugely advantageous -- if it doesn't already exist... I don't think it does

Re: custom memory management

2014-02-27 Thread Simon Bürger
On Thursday, 27 February 2014 at 22:04:50 UTC, Namespace wrote: A struct is a value type. So it is passed by value and is placed on the stack. { S s; } S DTor is called at the end of the scope. So you can rely on RAII as long as you use structs. On the stack yes. But not on the heap:

Re: custom memory management

2014-02-27 Thread Namespace
A struct is a value type. So it is passed by value and is placed on the stack. { S s; } S DTor is called at the end of the scope. So you can rely on RAII as long as you use structs.

custom memory management

2014-02-27 Thread Simon Bürger
I am trying to implement a structure with value semantics which uses an internal buffer. The first approach looks like this: struct S { byte[] buf; this(int size) { buf = new byte[size]; } this(this) { buf = buf.dup; } ~this(this) { delete buf; } } T

Re: Rust style memory management in D?

2014-01-12 Thread Rikki Cattermole
Please post on[0] regarding better memory management. As currently work is being done on rewriting the GC (which really was needed). [0] http://forum.dlang.org/post/lao9fn$1d70$1...@digitalmars.com

Rust style memory management in D?

2014-01-12 Thread Walter Gray
y awful for such an elegant language. Every area but memory management is beautiful and can do what you like, but trying to avoid the GC is downright painful and forces you to ditch much of the safety D provides. Given that it is designed to be a systems programming language & in such applicatio

Re: non-determinant object lifetime and memory management

2013-12-01 Thread Frustrated
On Sunday, 1 December 2013 at 02:29:42 UTC, bioinfornatics wrote: 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

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 except

Re: non-determinant object lifetime and memory management

2013-11-30 Thread Frustrated
On Saturday, 30 November 2013 at 12:51:46 UTC, Rene Zwanenburg wrote: 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

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 except

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 ptr

  1   2   >