Jump to page: 1 24  
Page
Thread overview
June 11

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 has and what things I should watch out for. Also, I want to know what high level features I will be missing.
Thanks in advance.

June 11
On Tuesday, 11 June 2024 at 13:00:50 UTC, Vinod K Chandran wrote:
> ...

Similar posts that may help:

https://forum.dlang.org/thread/hryadrwplyezihwagiox@forum.dlang.org

https://forum.dlang.org/thread/dblfikgnzqfmmglwdxdg@forum.dlang.org

Matheus.
June 11
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/hryadrwplyezihwagiox@forum.dlang.org
>
> https://forum.dlang.org/thread/dblfikgnzqfmmglwdxdg@forum.dlang.org
>
> Matheus.
Thank you Matheus, let me check that. :)

June 11
  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, where @nogc is a nuisance
  5. polymorphism can be a little quirky
June 11

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 an exception or you don't
  4. I occasionally use CTFE, where @nogc is a nuisance
  5. polymorphism can be a little quirky

Oh thank you @Kagamin. That's some valuable comments. I will take special care.

June 11
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 exceptions as boolean: you either have an exception or you don't
> 4) I occasionally use CTFE, where `@nogc` is a nuisance
> 5) polymorphism can be a little quirky

June 11

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 has and what things I should watch out for. Also, I want to know what high level features I will be missing.
Thanks in advance.

I could answer the question directly, but it seems others have already done so.

I would instead ask the reason for wanting to write D code without the GC. In many cases, you can write code without regularly using the GC (i.e. preallocate, or reuse buffers), but still use the GC in the sense that it is there as your allocator.

A great example is exceptions. Something that has the code throw new Exception(...) is going to need the GC in order to build that exception. But if your code is written such that this never (normally) happens, then you aren't using the GC for that code.

So I would call this kind of style writing code that avoids creating garbage. To me, this is the most productive way to minimize GC usage, while still allowing one to use D as it was intended.

-Steve

June 11

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. It will give finer control to me.
  2. To squeeze out the last bit of performance from D.
June 12

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 assuming that manual memory management is better for this project. It will give finer control to me.
  2. To squeeze out the last bit of performance from D.

rather then worring about the gc, just have 95% of data on the stack

June 12

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 assuming that manual memory management is better for this project. It will give finer control to me.
  2. To squeeze out the last bit of performance from D.

the GC only runs on allocation. if you want to squeeze out the last bit of performance, you should preallocate all bufferes anyway, and GC vs no GC doesn't matter.
also just slap @nogc on your main function to avoid accidential allocations.

« First   ‹ Prev
1 2 3 4