Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: recommended construction/destruction patterns for manual memory management #3973

Open
dlangBugzillaToGithub opened this issue Mar 15, 2018 · 2 comments

Comments

@dlangBugzillaToGithub
Copy link

Manu reported this on 2018-03-15T00:33:06Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=18613

CC List

  • Seb

Description

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.
```
@dlangBugzillaToGithub
Copy link
Author

greeenify commented on 2018-03-15T06:17:18Z

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).

@dlangBugzillaToGithub
Copy link
Author

turkeyman commented on 2018-03-15T06:46:57Z

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant