digitalmars.D.learn - Why free and realloc seem to include .
- Michael (11/16) Aug 03 2017 So this might be a bit of a stupid question, but looking at the
- Temtaime (3/20) Aug 03 2017 Dot is equal to C++'s :: operator to access a global namespace.
- Michael (3/24) Aug 03 2017 I've not seen that either, though I'm not a C++ programmer. Does
- Adam D. Ruppe (10/13) Aug 03 2017 Consider the following:
- Michael (3/16) Aug 03 2017 So it could be used without, but you risk conflicts with other
So this might be a bit of a stupid question, but looking at the DMD source code (dmodule.d in particular) I see the following code:if (srcfile._ref == 0) .free(srcfile.buffer); srcfile.buffer = null; srcfile.len = 0;and I was just wondering why certain functions seem to be called using the dot operator on its own, unattached to some object. This is probably a naive question but I haven't seen this in my limited experience using D and I was just wondering why this is. I have only really seen this relating to D's manual memory management. But in the same file, I see examples like this:FileName.free(n);so what is the case when you should use .free() and why not just free()? Thanks.
Aug 03 2017
On Thursday, 3 August 2017 at 14:03:56 UTC, Michael wrote:So this might be a bit of a stupid question, but looking at the DMD source code (dmodule.d in particular) I see the following code:Dot is equal to C++'s :: operator to access a global namespace. Aka ::free(ptr);if (srcfile._ref == 0) .free(srcfile.buffer); srcfile.buffer = null; srcfile.len = 0;and I was just wondering why certain functions seem to be called using the dot operator on its own, unattached to some object. This is probably a naive question but I haven't seen this in my limited experience using D and I was just wondering why this is. I have only really seen this relating to D's manual memory management. But in the same file, I see examples like this:FileName.free(n);so what is the case when you should use .free() and why not just free()? Thanks.
Aug 03 2017
On Thursday, 3 August 2017 at 14:15:40 UTC, Temtaime wrote:On Thursday, 3 August 2017 at 14:03:56 UTC, Michael wrote:I've not seen that either, though I'm not a C++ programmer. Does using free() on its own not assume access of a global namespace?So this might be a bit of a stupid question, but looking at the DMD source code (dmodule.d in particular) I see the following code:Dot is equal to C++'s :: operator to access a global namespace. Aka ::free(ptr);[...]and I was just wondering why certain functions seem to be called using the dot operator on its own, unattached to some object. This is probably a naive question but I haven't seen this in my limited experience using D and I was just wondering why this is. I have only really seen this relating to D's manual memory management. But in the same file, I see examples like this:[...]so what is the case when you should use .free() and why not just free()? Thanks.
Aug 03 2017
On Thursday, 3 August 2017 at 15:18:17 UTC, Michael wrote:I've not seen that either, though I'm not a C++ programmer. Does using free() on its own not assume access of a global namespace?Consider the following: class Foo { void free(void*); void other_method() { free(ptr); // calls the member function } } The leading dot in D just ensures it calls the global one instead of a member (if present).
Aug 03 2017
On Thursday, 3 August 2017 at 15:29:29 UTC, Adam D. Ruppe wrote:On Thursday, 3 August 2017 at 15:18:17 UTC, Michael wrote:So it could be used without, but you risk conflicts with other functions. I got it, thanks to both of you.I've not seen that either, though I'm not a C++ programmer. Does using free() on its own not assume access of a global namespace?Consider the following: class Foo { void free(void*); void other_method() { free(ptr); // calls the member function } } The leading dot in D just ensures it calls the global one instead of a member (if present).
Aug 03 2017