www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - automem v0.3.5 - now with more vector (like std::vector, not Physics)!

reply Atila Neves <atila.neves gmail.com> writes:
If you've never heard of automem before, I wrote it to have 
C++-style smart pointers in D that I could use in  nogc code:


http://code.dlang.org/packages/automem


I needed something like a std::vector that can be  nogc so I 
wrote it. I wondered whether or not to put it in a collections 
package or not, then punted on the decision and just stuck it in 
automem. Anyway, code:


     // *no* GC allocations below if theAllocator is set to an 
allocator that
     // never allocates on the GC heap

     import automem.vector;  // there's an `array` alias too
     auto v = vector(0, 1, 2);
     v ~= 3;
     v ~= only(4, 5);
     assert(v[] == [0, 1, 2, 3, 4, 5]);


If you want the  nogc compile-time guarantee, specify an 
allocator:

     ()  nogc {
         auto v = vector!Mallocator(0, 1, 2, 3);
         v ~= only(4, 5, 6);
         // etc.
     }();


Enjoy (hopefully)!
Sep 20 2018
next sibling parent 12345swordy <alexanderheistermann gmail.com> writes:
On Thursday, 20 September 2018 at 14:57:42 UTC, Atila Neves wrote:
 If you've never heard of automem before, I wrote it to have 
 C++-style smart pointers in D that I could use in  nogc code:

 [...]
Official bindings to std::vector will soon be added by manu. (I think)
Sep 20 2018
prev sibling parent reply ikod <geller.garry gmail.com> writes:
On Thursday, 20 September 2018 at 14:57:42 UTC, Atila Neves wrote:
 If you've never heard of automem before, I wrote it to have 
 C++-style smart pointers in D that I could use in  nogc code:


 http://code.dlang.org/packages/automem
Sorry for asking here. Shouldn't this code work? import automem; struct X { int i; } struct Y { RefCounted!X x; // fails //X x; // ok } void main() { Y y1; Y y2; y2 = y1; } https://run.dlang.io/is/k2qWhm
Sep 30 2018
parent Atila Neves <atila.neves gmail.com> writes:
On Sunday, 30 September 2018 at 19:54:07 UTC, ikod wrote:
 On Thursday, 20 September 2018 at 14:57:42 UTC, Atila Neves 
 wrote:
 If you've never heard of automem before, I wrote it to have 
 C++-style smart pointers in D that I could use in  nogc code:


 http://code.dlang.org/packages/automem
Sorry for asking here. Shouldn't this code work? import automem; struct X { int i; } struct Y { RefCounted!X x; // fails //X x; // ok } void main() { Y y1; Y y2; y2 = y1; } https://run.dlang.io/is/k2qWhm
This really should have been a github issue, but thanks for posting this anyway. I just fixed it.
Oct 01 2018