Re: How to use D without the GC ?

2024-06-14 Thread Dukc via Digitalmars-d-learn
bachmeier kirjoitti 14.6.2024 klo 16.48: See the example I posted elsewhere in this thread: https://forum.dlang.org/post/mwerxaolbkuxlgfep...@forum.dlang.org I defined ``` @nogc ~this() {   free(ptr);   printf("Data has been freed\n"); } ``` and that gets called when the reference count hit

Re: How to use D without the GC ?

2024-06-14 Thread bachmeier via Digitalmars-d-learn
On Friday, 14 June 2024 at 07:52:35 UTC, Dukc wrote: Lance Bachmeier kirjoitti 14.6.2024 klo 4.23: We must be talking about different things. You could, for instance, call a function in a C library to allocate memory at runtime. That function returns a pointer and you pass it to SafeRefCounted

Re: How to use D without the GC ?

2024-06-14 Thread Dukc via Digitalmars-d-learn
Lance Bachmeier kirjoitti 14.6.2024 klo 4.23: We must be talking about different things. You could, for instance, call a function in a C library to allocate memory at runtime. That function returns a pointer and you pass it to SafeRefCounted to ensure it gets freed. Nothing is known about the a

Re: How to use D without the GC ?

2024-06-13 Thread Lance Bachmeier via Digitalmars-d-learn
On Thursday, 13 June 2024 at 07:18:48 UTC, Dukc wrote: Lance Bachmeier kirjoitti 13.6.2024 klo 1.32: Why would it be different from calling malloc and free manually? I guess I'm not understanding, because you put the same calls to malloc and free that you'd otherwise be doing inside this and

Re: How to use D without the GC ?

2024-06-13 Thread Dukc via Digitalmars-d-learn
Dukc kirjoitti 13.6.2024 klo 10.18: So for example, if you have a program that sometimes needs 600Mib and sometimes needs 1100MiB, you can in any case allocate all that in one go with one `malloc` or one `new`, but you'll need at least 38/59 `SafeRefCounted` static arrays, and therefore `malloc

Re: How to use D without the GC ?

2024-06-13 Thread Dukc via Digitalmars-d-learn
Lance Bachmeier kirjoitti 13.6.2024 klo 1.32: Why would it be different from calling malloc and free manually? I guess I'm not understanding, because you put the same calls to malloc and free that you'd otherwise be doing inside this and ~this. Because with `SafeRefCounted`, you have to deci

Re: How to use D without the GC ?

2024-06-12 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 12 June 2024 at 16:50:04 UTC, Vinod K Chandran wrote: On Wednesday, 12 June 2024 at 01:35:26 UTC, monkyyy wrote: rather then worring about the gc, just have 95% of data on the stack How's that even possible ? AFAIK, we need heap allocated memory in order to make GUI lib as a D

Re: How to use D without the GC ?

2024-06-12 Thread Lance Bachmeier via Digitalmars-d-learn
On Wednesday, 12 June 2024 at 21:59:54 UTC, drug007 wrote: Yes, but you get all the benefits of `double[]` for free if you do it that way, including the more concise foo[10] syntax. I meant you do not need to add `ptr` field at all I see. You're right. I thought it would be easier for someon

Re: How to use D without the GC ?

2024-06-12 Thread Lance Bachmeier via Digitalmars-d-learn
On Wednesday, 12 June 2024 at 21:36:30 UTC, Dukc wrote: bachmeier kirjoitti 12.6.2024 klo 18.21: You're splitting things into GC-allocated memory and manually managed memory. There's also SafeRefCounted, which handles the malloc and free for you. I suspect `SafeRefCounted` (or `RefCounted`) i

Re: How to use D without the GC ?

2024-06-12 Thread drug007 via Digitalmars-d-learn
On 12.06.2024 23:56, bachmeier wrote: On Wednesday, 12 June 2024 at 20:37:36 UTC, drug007 wrote: On 12.06.2024 21:57, bachmeier wrote: On Wednesday, 12 June 2024 at 18:36:26 UTC, Vinod K Chandran wrote: On Wednesday, 12 June 2024 at 15:33:39 UTC, bachmeier wrote: A SafeRefCounted example with

Re: How to use D without the GC ?

2024-06-12 Thread Dukc via Digitalmars-d-learn
bachmeier kirjoitti 12.6.2024 klo 18.21: You're splitting things into GC-allocated memory and manually managed memory. There's also SafeRefCounted, which handles the malloc and free for you. I suspect `SafeRefCounted` (or `RefCounted`) is not the best fit for this scenario. The problem with i

Re: How to use D without the GC ?

2024-06-12 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 12 June 2024 at 20:37:36 UTC, drug007 wrote: On 12.06.2024 21:57, bachmeier wrote: On Wednesday, 12 June 2024 at 18:36:26 UTC, Vinod K Chandran wrote: On Wednesday, 12 June 2024 at 15:33:39 UTC, bachmeier wrote: A SafeRefCounted example with main marked @nogc: ``` import std; im

Re: How to use D without the GC ?

2024-06-12 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 12 June 2024 at 20:31:34 UTC, Vinod K Chandran wrote: On Wednesday, 12 June 2024 at 18:57:41 UTC, bachmeier wrote: Try `foo[10] = 1.5` and `foo.ptr[10] = 1.5`. The first correctly throws an out of bounds error. The second gives `Segmentation fault (core dumped)`. We can use it

Re: How to use D without the GC ?

2024-06-12 Thread drug007 via Digitalmars-d-learn
On 12.06.2024 21:57, bachmeier wrote: On Wednesday, 12 June 2024 at 18:36:26 UTC, Vinod K Chandran wrote: On Wednesday, 12 June 2024 at 15:33:39 UTC, bachmeier wrote: A SafeRefCounted example with main marked @nogc: ``` import std; import core.stdc.stdlib; struct Foo {   double[] data;   doub

Re: How to use D without the GC ?

2024-06-12 Thread Vinod K Chandran via Digitalmars-d-learn
On Wednesday, 12 June 2024 at 18:57:41 UTC, bachmeier wrote: Try `foo[10] = 1.5` and `foo.ptr[10] = 1.5`. The first correctly throws an out of bounds error. The second gives `Segmentation fault (core dumped)`. We can use it like this, i think. ``` struct Foo { double * ptr; uint capacity

Re: How to use D without the GC ?

2024-06-12 Thread Vinod K Chandran via Digitalmars-d-learn
On Wednesday, 12 June 2024 at 18:58:49 UTC, evilrat wrote: the only problem is that it seems to leak a lot PydObjects so i have to manually free them, even scope doesn't helps with that which is sad. Oh I see. I did some experiments with nimpy and pybind11. Both experiments were resulted in

Re: How to use D without the GC ?

2024-06-12 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Wednesday, 12 June 2024 at 18:58:49 UTC, evilrat wrote: On Wednesday, 12 June 2024 at 17:00:14 UTC, Vinod K Chandran wrote: [...] It is probably not that well maintained, but it definitely works with python 3.10 and maybe even 3.11, i use it to interface with pytorch and numpy and PIL, bu

Re: How to use D without the GC ?

2024-06-12 Thread evilrat via Digitalmars-d-learn
On Wednesday, 12 June 2024 at 17:00:14 UTC, Vinod K Chandran wrote: On Wednesday, 12 June 2024 at 10:16:26 UTC, Sergey wrote: Btw are you going to use PyD or doing everything manually from scratch? Does PyD active now ? I didn't tested it. My approach is using "ctypes" library with my dll.

Re: How to use D without the GC ?

2024-06-12 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 12 June 2024 at 18:36:26 UTC, Vinod K Chandran wrote: On Wednesday, 12 June 2024 at 15:33:39 UTC, bachmeier wrote: A SafeRefCounted example with main marked @nogc: ``` import std; import core.stdc.stdlib; struct Foo { double[] data; double * ptr; alias data this; @nogc t

Re: How to use D without the GC ?

2024-06-12 Thread Vinod K Chandran via Digitalmars-d-learn
On Wednesday, 12 June 2024 at 15:33:39 UTC, bachmeier wrote: A SafeRefCounted example with main marked @nogc: ``` import std; import core.stdc.stdlib; struct Foo { double[] data; double * ptr; alias data this; @nogc this(int n) { ptr = cast(double*) malloc(n*double.sizeof); dat

Re: How to use D without the GC ?

2024-06-12 Thread Vinod K Chandran via Digitalmars-d-learn
On Wednesday, 12 June 2024 at 15:33:39 UTC, bachmeier wrote: A SafeRefCounted example with main marked @nogc: Thanks for the sample. It looks tempting! Let me check that.

Re: How to use D without the GC ?

2024-06-12 Thread Vinod K Chandran via Digitalmars-d-learn
On Wednesday, 12 June 2024 at 15:21:22 UTC, bachmeier wrote: You're splitting things into GC-allocated memory and manually managed memory. There's also SafeRefCounted, which handles the malloc and free for you. Thanks, I have read about the possibilities of "using malloc and free from D" in

Re: How to use D without the GC ?

2024-06-12 Thread Vinod K Chandran via Digitalmars-d-learn
On Wednesday, 12 June 2024 at 10:16:26 UTC, Sergey wrote: Btw are you going to use PyD or doing everything manually from scratch? Does PyD active now ? I didn't tested it. My approach is using "ctypes" library with my dll. Ctypes is the fastes FFI in my experience. I tested Cython, Pybind11

Re: How to use D without the GC ?

2024-06-12 Thread Vinod K Chandran via Digitalmars-d-learn
On Wednesday, 12 June 2024 at 09:44:05 UTC, DrDread wrote: also just slap @nogc on your main function to avoid accidential allocations. Thanks for the suggestion. Let me check that idea.

Re: How to use D without the GC ?

2024-06-12 Thread Vinod K Chandran via Digitalmars-d-learn
On Wednesday, 12 June 2024 at 01:35:26 UTC, monkyyy wrote: rather then worring about the gc, just have 95% of data on the stack How's that even possible ? AFAIK, we need heap allocated memory in order to make GUI lib as a DLL. So creating things in heap and modify it, that's the nature of m

Re: How to use D without the GC ?

2024-06-12 Thread bachmeier via Digitalmars-d-learn
A SafeRefCounted example with main marked @nogc: ``` import std; import core.stdc.stdlib; struct Foo { double[] data; double * ptr; alias data this; @nogc this(int n) { ptr = cast(double*) malloc(n*double.sizeof); data = ptr[0..n]; printf("Data has been allocated\n"); }

Re: How to use D without the GC ?

2024-06-12 Thread Sergey via Digitalmars-d-learn
On Tuesday, 11 June 2024 at 17:15:07 UTC, Vinod K Chandran wrote: On Tuesday, 11 June 2024 at 16:54:44 UTC, Steven Schveighoffer wrote: Two reasons. 1. I am writting a dll to use in Python. So I am assuming that Btw are you going to use PyD or doing everything manually from scratch?

Re: How to use D without the GC ?

2024-06-12 Thread DrDread via Digitalmars-d-learn
On Tuesday, 11 June 2024 at 17:15:07 UTC, Vinod K Chandran wrote: On Tuesday, 11 June 2024 at 16:54:44 UTC, Steven Schveighoffer wrote: I would instead ask the reason for wanting to write D code without the GC. -Steve Hi Steve, Two reasons. 1. I am writting a dll to use in Python. So I am

Re: How to use D without the GC ?

2024-06-11 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 11 June 2024 at 17:15:07 UTC, Vinod K Chandran wrote: On Tuesday, 11 June 2024 at 16:54:44 UTC, Steven Schveighoffer wrote: I would instead ask the reason for wanting to write D code without the GC. -Steve Hi Steve, Two reasons. 1. I am writting a dll to use in Python. So I am

Re: How to use D without the GC ?

2024-06-11 Thread Vinod K Chandran via Digitalmars-d-learn
On Tuesday, 11 June 2024 at 16:54:44 UTC, Steven Schveighoffer wrote: I would instead ask the reason for wanting to write D code without the GC. -Steve Hi Steve, Two reasons. 1. I am writting a dll to use in Python. So I am assuming that manual memory management is better for this project

Re: How to use D without the GC ?

2024-06-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 11 June 2024 at 13:00:50 UTC, Vinod K Chandran wrote: Hi all, I am planning to write some D code without GC. But I have no prior experience with it. I have experience using manual memory management languages. But D has so far been used with GC. So I want to know what pitfalls it ha

Re: How to use D without the GC ?

2024-06-11 Thread drug007 via Digitalmars-d-learn
On 11.06.2024 17:59, Kagamin wrote: 1) arena allocator makes memory manageable with occasional cache invalidation problem 2) no hashtable no problem [OT] could you elaborate what problems they cause? 3) error handling depends on your code complexity, but even in complex C# code I found excep

Re: How to use D without the GC ?

2024-06-11 Thread Vinod K Chandran via Digitalmars-d-learn
On Tuesday, 11 June 2024 at 14:59:24 UTC, Kagamin wrote: 1) arena allocator makes memory manageable with occasional cache invalidation problem 2) no hashtable no problem 3) error handling depends on your code complexity, but even in complex C# code I found exceptions as boolean: you either have

Re: How to use D without the GC ?

2024-06-11 Thread Kagamin via Digitalmars-d-learn
1) arena allocator makes memory manageable with occasional cache invalidation problem 2) no hashtable no problem 3) error handling depends on your code complexity, but even in complex C# code I found exceptions as boolean: you either have an exception or you don't 4) I occasionally use CTFE, w

Re: How to use D without the GC ?

2024-06-11 Thread Vinod K Chandran via Digitalmars-d-learn
On Tuesday, 11 June 2024 at 13:35:19 UTC, matheus wrote: On Tuesday, 11 June 2024 at 13:00:50 UTC, Vinod K Chandran wrote: ... Similar posts that may help: https://forum.dlang.org/thread/hryadrwplyezihwag...@forum.dlang.org https://forum.dlang.org/thread/dblfikgnzqfmmglwd...@forum.dlang.org

Re: How to use D without the GC ?

2024-06-11 Thread matheus via Digitalmars-d-learn
On Tuesday, 11 June 2024 at 13:00:50 UTC, Vinod K Chandran wrote: ... Similar posts that may help: https://forum.dlang.org/thread/hryadrwplyezihwag...@forum.dlang.org https://forum.dlang.org/thread/dblfikgnzqfmmglwd...@forum.dlang.org Matheus.