www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Module for manual memory management

reply "Foo" <Foo test.de> writes:
Is there interest in such a thing?
I'm currently working on something for my own use and I'm curious 
if anyone else would be interested in something like that.
I'm aware of Unique, RefCounted, Scoped, emplace and so on, but 
I'm not a big fan of some implementations (in my opinion not much 
of it follows the KISS principle). Also, as far as I remember, 
RefCounted and Unique are somewhat outdated.
As said I'm just curious and I'm aware that my code may be 
somewhat un-phobos like.

My current stand is this: http://dpaste.dzfl.pl/f1423322b7d5
Just to make it clear: m3 = manual memory management = mmm = m3

and here is some test code: http://dpaste.dzfl.pl/026013fbe19f

I repeat: I know that I reimplement some logic like emplace and 
that my version is shorter but maybe not quite correct/incomplete.
And I'm also aware of std.allocator and so on, but that is 
something different IMO.
Jan 30 2015
next sibling parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 1/30/15 3:49 PM, Foo wrote:
 Is there interest in such a thing?
 I'm currently working on something for my own use and I'm curious if
 anyone else would be interested in something like that.
 I'm aware of Unique, RefCounted, Scoped, emplace and so on, but I'm not
 a big fan of some implementations (in my opinion not much of it follows
 the KISS principle). Also, as far as I remember, RefCounted and Unique
 are somewhat outdated.
 As said I'm just curious and I'm aware that my code may be somewhat
 un-phobos like.

 My current stand is this: http://dpaste.dzfl.pl/f1423322b7d5
 Just to make it clear: m3 = manual memory management = mmm = m3

 and here is some test code: http://dpaste.dzfl.pl/026013fbe19f

 I repeat: I know that I reimplement some logic like emplace and that my
 version is shorter but maybe not quite correct/incomplete.
So why come with your own self-admitted incomplete/incorrect alternatives instead of adding/improving the standard ones? If something's there that shouldn't, remove it. I don't get this "I didn't get it so I'll redo it incompletely".
 And I'm also aware of std.allocator and so on, but that is something
 different IMO.
Agreed. Andrei
Jan 30 2015
next sibling parent "Foo" <Foo test.de> writes:
On Saturday, 31 January 2015 at 01:07:21 UTC, Andrei Alexandrescu 
wrote:
 On 1/30/15 3:49 PM, Foo wrote:
 Is there interest in such a thing?
 I'm currently working on something for my own use and I'm 
 curious if
 anyone else would be interested in something like that.
 I'm aware of Unique, RefCounted, Scoped, emplace and so on, 
 but I'm not
 a big fan of some implementations (in my opinion not much of 
 it follows
 the KISS principle). Also, as far as I remember, RefCounted 
 and Unique
 are somewhat outdated.
 As said I'm just curious and I'm aware that my code may be 
 somewhat
 un-phobos like.

 My current stand is this: http://dpaste.dzfl.pl/f1423322b7d5
 Just to make it clear: m3 = manual memory management = mmm = m3

 and here is some test code: http://dpaste.dzfl.pl/026013fbe19f

 I repeat: I know that I reimplement some logic like emplace 
 and that my
 version is shorter but maybe not quite correct/incomplete.
So why come with your own self-admitted incomplete/incorrect alternatives instead of adding/improving the standard ones? If something's there that shouldn't, remove it. I don't get this "I didn't get it so I'll redo it incompletely".
Too much and too long code. ;) Sometimes it is better to see a new version from scratch to rethink old ones. ;) I'm not for removing them, I'm for rebuilding them. And a new version can bring new wind into the sails. That's why I'm presented my code here: for discussion. But that is not that important, my main target was the implementation of Unique and Shared. You can adapt them with minimal effort. But I'm quite sure that my 'make' function is not yet present in phobos. So, what do you think about discussing if and how my make, Unique and Shared could improve phobos.
 And I'm also aware of std.allocator and so on, but that is 
 something
 different IMO.
Agreed. Andrei
Jan 31 2015
prev sibling parent "Foo" <Foo test.de> writes:
On Saturday, 31 January 2015 at 01:07:21 UTC, Andrei Alexandrescu 
wrote:
 On 1/30/15 3:49 PM, Foo wrote:
 Is there interest in such a thing?
 I'm currently working on something for my own use and I'm 
 curious if
 anyone else would be interested in something like that.
 I'm aware of Unique, RefCounted, Scoped, emplace and so on, 
 but I'm not
 a big fan of some implementations (in my opinion not much of 
 it follows
 the KISS principle). Also, as far as I remember, RefCounted 
 and Unique
 are somewhat outdated.
 As said I'm just curious and I'm aware that my code may be 
 somewhat
 un-phobos like.

 My current stand is this: http://dpaste.dzfl.pl/f1423322b7d5
 Just to make it clear: m3 = manual memory management = mmm = m3

 and here is some test code: http://dpaste.dzfl.pl/026013fbe19f

 I repeat: I know that I reimplement some logic like emplace 
 and that my
 version is shorter but maybe not quite correct/incomplete.
So why come with your own self-admitted incomplete/incorrect alternatives instead of adding/improving the standard ones? If something's there that shouldn't, remove it. I don't get this "I didn't get it so I'll redo it incompletely".
 And I'm also aware of std.allocator and so on, but that is 
 something
 different IMO.
Agreed. Andrei
And I did not literally said 'incorrect'. I said _maybe_ incomplete. In my tests it works properly. What I meant with 'not quite correct' was that it isn't well tested _yet_. But that can be done later.
Jan 31 2015
prev sibling parent reply "Foo" <Foo test.de> writes:
For what it's worth, today I finished the current work. Now we 
will start working with it. If someone has critique, improvement 
suggestions or want to take some ideas, he is free to do so.
To repeat myself: we rewrote some functionality which already 
existed in D, but were improvable. For example the existing 
emplace method is quite long, hard to understand / read and is 
not marked with  nogc. Since we want to avoid the GC wherever 
possible we had to rewrite it. I hope it's useful for someone 
else and that some of you guys take some ideas from it.

https://github.com/Dgame/m3
Feb 04 2015
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 2/4/15 9:13 AM, Foo wrote:
 For what it's worth, today I finished the current work. Now we will
 start working with it. If someone has critique, improvement suggestions
 or want to take some ideas, he is free to do so.
 To repeat myself: we rewrote some functionality which already existed in
 D, but were improvable. For example the existing emplace method is quite
 long, hard to understand / read and is not marked with  nogc. Since we
 want to avoid the GC wherever possible we had to rewrite it. I hope it's
 useful for someone else and that some of you guys take some ideas from it.

 https://github.com/Dgame/m3
Opened File.d at random: trusted nogc char[] read(const string filename) nothrow { import std.c.stdio : FILE, SEEK_END, SEEK_SET, fopen, fclose, fseek, ftell, fread; FILE* f = fopen(filename.ptr, READ_BINARY); scope(exit) fclose(f); fseek(f, 0, SEEK_END); immutable size_t fsize = ftell(f); fseek(f, 0, SEEK_SET); char[] str = m3.m3.make!(char[])(fsize); fread(str.ptr, fsize, 1, f); return str; } Then stopped right there. This is nowhere near production quality - there is no error checking whatsoever, does more operations than necessary, won't work on special files etc. etc. etc. I applaud the intention but there is a lot more work to be done on this before it's in reviewable form. Andrei
Feb 04 2015
next sibling parent reply "Foo" <Foo test.de> writes:
On Wednesday, 4 February 2015 at 20:15:37 UTC, Andrei 
Alexandrescu wrote:
 On 2/4/15 9:13 AM, Foo wrote:
 For what it's worth, today I finished the current work. Now we 
 will
 start working with it. If someone has critique, improvement 
 suggestions
 or want to take some ideas, he is free to do so.
 To repeat myself: we rewrote some functionality which already 
 existed in
 D, but were improvable. For example the existing emplace 
 method is quite
 long, hard to understand / read and is not marked with  nogc. 
 Since we
 want to avoid the GC wherever possible we had to rewrite it. I 
 hope it's
 useful for someone else and that some of you guys take some 
 ideas from it.

 https://github.com/Dgame/m3
Opened File.d at random: trusted nogc char[] read(const string filename) nothrow { import std.c.stdio : FILE, SEEK_END, SEEK_SET, fopen, fclose, fseek, ftell, fread; FILE* f = fopen(filename.ptr, READ_BINARY); scope(exit) fclose(f); fseek(f, 0, SEEK_END); immutable size_t fsize = ftell(f); fseek(f, 0, SEEK_SET); char[] str = m3.m3.make!(char[])(fsize); fread(str.ptr, fsize, 1, f); return str; } Then stopped right there. This is nowhere near production quality - there is no error checking whatsoever, does more operations than necessary, won't work on special files etc. etc. etc. I applaud the intention but there is a lot more work to be done on this before it's in reviewable form. Andrei
Yes that is correct, currently there is no error checking, maybe it get that later. But what do you mean with "it use more operations than necessary"? I can't see it. But both points are helpful critique. Thanks a lot! :) As I said above, it's currently only for our work. But I presented it here, so that some guys can get some inspiration or can reuse our code. :) Maybe, but really only maybe, I will get some work done, so that it's is ready for phobos. But since such a review can take years, I see no use to do that work. But if someone else has the will to do that, reuse our code!
Feb 04 2015
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 2/4/2015 12:42 PM, Foo wrote:
 On Wednesday, 4 February 2015 at 20:15:37 UTC, Andrei Alexandrescu wrote:
  trusted
  nogc
 char[] read(const string filename) nothrow {
Yes that is correct, currently there is no error checking, maybe it get that later. But what do you mean with "it use more operations than necessary"? I can't see it. But both points are helpful critique. Thanks a lot! :)
No need to reinvent this: https://github.com/D-Programming-Language/phobos/blob/master/std/file.d line 194 Just use it and change the allocator bit.
Feb 04 2015
next sibling parent "Foo" <Foo test.de> writes:
On Wednesday, 4 February 2015 at 20:55:59 UTC, Walter Bright 
wrote:
 On 2/4/2015 12:42 PM, Foo wrote:
 On Wednesday, 4 February 2015 at 20:15:37 UTC, Andrei 
 Alexandrescu wrote:
  trusted
  nogc
 char[] read(const string filename) nothrow {
Yes that is correct, currently there is no error checking, maybe it get that later. But what do you mean with "it use more operations than necessary"? I can't see it. But both points are helpful critique. Thanks a lot! :)
No need to reinvent this: https://github.com/D-Programming-Language/phobos/blob/master/std/file.d line 194 Just use it and change the allocator bit.
Yes, I've also looked at that. But I think my code is more readable and easier to understand. But I will take a second look. ;) https://github.com/D-Programming-Language/phobos/blob/master/std/file.d#L194 just click on the line number on the left.
Feb 04 2015
prev sibling next sibling parent "Foo" <Foo test.de> writes:
On Wednesday, 4 February 2015 at 20:55:59 UTC, Walter Bright
wrote:
 On 2/4/2015 12:42 PM, Foo wrote:
 On Wednesday, 4 February 2015 at 20:15:37 UTC, Andrei 
 Alexandrescu wrote:
  trusted
  nogc
 char[] read(const string filename) nothrow {
Yes that is correct, currently there is no error checking, maybe it get that later. But what do you mean with "it use more operations than necessary"? I can't see it. But both points are helpful critique. Thanks a lot! :)
No need to reinvent this: https://github.com/D-Programming-Language/phobos/blob/master/std/file.d line 194 Just use it and change the allocator bit.
It would be much easier for me, if some of you would add such a allocator to it. :P
Feb 04 2015
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2015-02-04 21:55, Walter Bright wrote:

 No need to reinvent this:

    https://github.com/D-Programming-Language/phobos/blob/master/std/file.d
    line 194
Just for the record, you can get a link to the exact line by clicking on the line number in the left margin and the copying the link from the address bar. -- /Jacob Carlborg
Feb 07 2015
parent "Foo" <Foo test.de> writes:
On Saturday, 7 February 2015 at 11:29:51 UTC, Jacob Carlborg 
wrote:
 On 2015-02-04 21:55, Walter Bright wrote:

 No need to reinvent this:

   
 https://github.com/D-Programming-Language/phobos/blob/master/std/file.d
   line 194
Just for the record, you can get a link to the exact line by clicking on the line number in the left margin and the copying the link from the address bar.
The same I've said a page previously. Funny. :)
Feb 07 2015
prev sibling parent reply "Foo" <Foo test.de> writes:
On Wednesday, 4 February 2015 at 20:15:37 UTC, Andrei 
Alexandrescu wrote:
 On 2/4/15 9:13 AM, Foo wrote:
 For what it's worth, today I finished the current work. Now we 
 will
 start working with it. If someone has critique, improvement 
 suggestions
 or want to take some ideas, he is free to do so.
 To repeat myself: we rewrote some functionality which already 
 existed in
 D, but were improvable. For example the existing emplace 
 method is quite
 long, hard to understand / read and is not marked with  nogc. 
 Since we
 want to avoid the GC wherever possible we had to rewrite it. I 
 hope it's
 useful for someone else and that some of you guys take some 
 ideas from it.

 https://github.com/Dgame/m3
Opened File.d at random: trusted nogc char[] read(const string filename) nothrow { import std.c.stdio : FILE, SEEK_END, SEEK_SET, fopen, fclose, fseek, ftell, fread; FILE* f = fopen(filename.ptr, READ_BINARY); scope(exit) fclose(f); fseek(f, 0, SEEK_END); immutable size_t fsize = ftell(f); fseek(f, 0, SEEK_SET); char[] str = m3.m3.make!(char[])(fsize); fread(str.ptr, fsize, 1, f); return str; } Then stopped right there. This is nowhere near production quality - there is no error checking whatsoever, does more operations than necessary, won't work on special files etc. etc. etc. I applaud the intention but there is a lot more work to be done on this before it's in reviewable form. Andrei
I would be glad if you or Walter could review the other parts as well. I'm very sure that your review will be very helpful and I'm convinced that the modules Array or Smart Pointer could be useful for phobos.
Feb 04 2015
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 2/4/15 11:48 PM, Foo wrote:
 I would be glad if you or Walter could review the other parts as well.
 I'm very sure that your review will be very helpful and I'm convinced
 that the modules Array or Smart Pointer could be useful for phobos.
Your code is a ways from being in reviewable form. It would be great if a member of the community could act as a mentor. -- Andrei
Feb 04 2015
parent "Foo" <Foo test.de> writes:
On Thursday, 5 February 2015 at 07:53:34 UTC, Andrei Alexandrescu 
wrote:
 On 2/4/15 11:48 PM, Foo wrote:
 I would be glad if you or Walter could review the other parts 
 as well.
 I'm very sure that your review will be very helpful and I'm 
 convinced
 that the modules Array or Smart Pointer could be useful for 
 phobos.
Your code is a ways from being in reviewable form. It would be great if a member of the community could act as a mentor. -- Andrei
Oh, I didn't thought that it is so bad. :D It works splendidly so far for us. Sorry, that I'm wasting your time. :)
Feb 05 2015