D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 18613 - Documentation: recommended construction/destruction patterns for manual memory management
Summary: Documentation: recommended construction/destruction patterns for manual memor...
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dlang.org (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-03-15 00:33 UTC by Manu
Modified: 2024-12-15 15:24 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Manu 2018-03-15 00:33:06 UTC
A colleague couldn't find an article he expected to exist.
I'm posting this on his behalf, because bugzilla doesn't use github login credentials "yeah I literally clicked twice, was asked for login, closed :P"

```
Coming from C++ I was looking for delete after I did my new. I then found that there was no delete because of GC.
To stay close to my C++ approach I decided not to use GC which then prompted the issue, how do I call the dtor + free.
Current solution, make a function myDelete that calls dtor and free by hand.
Could use an article explaining the approach and highlighting pros and cons for each method. It would also be useful to have a section on what is the preferred way to do this manual memory management in D and why.
```
Comment 1 Seb 2018-03-15 06:17:18 UTC
Thanks a lot for opening the request on his behalf.
(We might modernize Bugzilla, so stay tuned)

Does your colleague know about the GC series?https://dlang.org/blog/the-gc-series

Also did your colleague find https://dlang.org/articles/cpptod.html?

Maybe this page could then be expanded.

> Current solution, make a function myDelete that calls dtor and free by hand.

The preferred way is to use make and dispose from std.experimental.allocator - they are the D analogies to malloc and free though a lot smarter (and dispose calls the destructor).
Comment 2 Manu 2018-03-15 06:46:57 UTC
He's interacting with existing C++ code, and doesn't want to have conflicting allocation strategies. It's gamedev, so custom allocation mechanisms are already in use.

He did find the cpptod, read it, but he suggested there were still questions. I'll dig for his thoughts at lunch tomorrow :)

I'll point him to std.experimental.allocator.

Thanks!
Comment 3 dlangBugzillaToGithub 2024-12-15 15:24:52 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dlang.org/issues/3973

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB