Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-28 Thread Atila Neves via Digitalmars-d-announce
On Sunday, 9 April 2017 at 15:52:50 UTC, Basile B. wrote: On Sunday, 9 April 2017 at 08:56:52 UTC, Atila Neves wrote: Using std.experimental.allocator? Tired of writing `scope(exit) allocator.dispose(foo);` in a language with RAII? Me too: http://code.dlang.org/packages/automem I think

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-17 Thread Stanislav Blinov via Digitalmars-d-announce
On Monday, 17 April 2017 at 13:21:50 UTC, Kagamin wrote: If we can control memory layout, we can do what shared_ptr does and couple the reference counter with the object, then we can have just one pointer: struct RefCounted(T) { struct Wrapper { int count; T payload; }

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-17 Thread Kagamin via Digitalmars-d-announce
On Wednesday, 12 April 2017 at 13:32:36 UTC, Stanislav Blinov wrote: Syntax is not the core of the issue, it's not about just marking a destructor as shared. Making RefCounted itself shared would require implementing some form of synchronization of all the 'dereference' operations, including

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-12 Thread Stanislav Blinov via Digitalmars-d-announce
On Monday, 10 April 2017 at 08:11:37 UTC, Atila Neves wrote: On Sunday, 9 April 2017 at 13:59:14 UTC, Andrei Alexandrescu wrote: Great. Can RefCounted itself be shared? I learned this is important for composition, i.e. you want to make a RefCounted a field in another object that is itself

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-11 Thread Atila Neves via Digitalmars-d-announce
On Tuesday, 11 April 2017 at 22:32:51 UTC, Martin Nowak wrote: On Monday, 10 April 2017 at 08:31:28 UTC, Atila Neves wrote: ```d import std.experimental.allocator.mallocator; UniqueArray!(int, Mallocator) a; a ~= [0,1]; ``` So the difference between std.container.Array and UniqueArray is

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-11 Thread Martin Nowak via Digitalmars-d-announce
On Monday, 10 April 2017 at 08:31:28 UTC, Atila Neves wrote: ```d import std.experimental.allocator.mallocator; UniqueArray!(int, Mallocator) a; a ~= [0,1]; ``` So the difference between std.container.Array and UniqueArray is that the latter supports allocators?

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-11 Thread Martin Nowak via Digitalmars-d-announce
On Tuesday, 11 April 2017 at 10:24:08 UTC, Nicholas Wilson wrote: In LDC we have an attribute for that `allocSize` (https://github.com/ldc-developers/druntime/blob/ldc/src/ldc/attributes.d#L16) perhaps this attribute should be used across compilers and be in druntime? Nice, if pure required

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-11 Thread Atila Neves via Digitalmars-d-announce
On Tuesday, 11 April 2017 at 08:09:15 UTC, Martin Nowak wrote: On Sunday, 9 April 2017 at 10:22:49 UTC, Atila Neves wrote: I did not. Thanks for telling me! The way I wrote it RefCounted!(shared T) works - RefCounted doesn't have to be shared itself, but I guess it could be. I think the

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-11 Thread Nicholas Wilson via Digitalmars-d-announce
On Tuesday, 11 April 2017 at 09:53:46 UTC, Martin Nowak wrote: I think we might be able to solve this problem in D by making IAllocator.allocate pure, which tells the compiler that this function returns a fresh piece of memory without any side-effect, i.e. enough information to optimize away

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-11 Thread Martin Nowak via Digitalmars-d-announce
On Sunday, 9 April 2017 at 13:59:14 UTC, Andrei Alexandrescu wrote: . The allocator has to be specified as part of the type: this means the user can choose how to store it in the smart pointer, which for singletons (e.g. Mallocator) or stateless allocators means they can take up zero space. If

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-11 Thread Nordlöw via Digitalmars-d-announce
On Sunday, 9 April 2017 at 08:56:52 UTC, Atila Neves wrote: http://code.dlang.org/packages/automem You might find my own containers interesting, especially https://github.com/nordlow/phobos-next/blob/master/src/array_ex.d Supports all the different ways I could think an array needs to work:

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-11 Thread Martin Nowak via Digitalmars-d-announce
On Sunday, 9 April 2017 at 10:22:49 UTC, Atila Neves wrote: I did not. Thanks for telling me! The way I wrote it RefCounted!(shared T) works - RefCounted doesn't have to be shared itself, but I guess it could be. I think the other design is slightly more correct, having a single thread own

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-10 Thread Atila Neves via Digitalmars-d-announce
On Sunday, 9 April 2017 at 19:04:22 UTC, mogu wrote: On Sunday, 9 April 2017 at 08:56:52 UTC, Atila Neves wrote: Using std.experimental.allocator? Tired of writing `scope(exit) allocator.dispose(foo);` in a language with RAII? Me too: [...] Nice! Should UniqueArray be implemented as a

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-10 Thread Atila Neves via Digitalmars-d-announce
On Sunday, 9 April 2017 at 15:52:50 UTC, Basile B. wrote: On Sunday, 9 April 2017 at 08:56:52 UTC, Atila Neves wrote: Using std.experimental.allocator? Tired of writing `scope(exit) allocator.dispose(foo);` in a language with RAII? Me too: http://code.dlang.org/packages/automem I think

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-10 Thread Atila Neves via Digitalmars-d-announce
On Sunday, 9 April 2017 at 13:59:14 UTC, Andrei Alexandrescu wrote: On 4/9/17 4:56 AM, Atila Neves wrote: Using std.experimental.allocator? Tired of writing `scope(exit) allocator.dispose(foo);` in a language with RAII? Me too: http://code.dlang.org/packages/automem Example: I think the

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-09 Thread mogu via Digitalmars-d-announce
On Sunday, 9 April 2017 at 08:56:52 UTC, Atila Neves wrote: Using std.experimental.allocator? Tired of writing `scope(exit) allocator.dispose(foo);` in a language with RAII? Me too: [...] Nice! Should UniqueArray be implemented as a overloaded version of Unique? Unique!(Object[]) instead

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-09 Thread Basile B. via Digitalmars-d-announce
On Sunday, 9 April 2017 at 08:56:52 UTC, Atila Neves wrote: Using std.experimental.allocator? Tired of writing `scope(exit) allocator.dispose(foo);` in a language with RAII? Me too: http://code.dlang.org/packages/automem I think that the Array misses - a reservation strategy, something

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-09 Thread rikki cattermole via Digitalmars-d-announce
On 09/04/2017 2:59 PM, Andrei Alexandrescu wrote: On 4/9/17 4:56 AM, Atila Neves wrote: snip . UniqueArray behaves nearly like a normal array. You can even append to it, but it won't use GC memory (unless, of course, you chose to use GCAllocator)! This may be a great candidate for the

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-09 Thread Andrei Alexandrescu via Digitalmars-d-announce
On 4/9/17 4:56 AM, Atila Neves wrote: Using std.experimental.allocator? Tired of writing `scope(exit) allocator.dispose(foo);` in a language with RAII? Me too: http://code.dlang.org/packages/automem Example: I think the code in the README should be enough to understand what's going on.

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-09 Thread Atila Neves via Digitalmars-d-announce
On Sunday, 9 April 2017 at 09:36:53 UTC, Martin Nowak wrote: On Sunday, 9 April 2017 at 08:56:52 UTC, Atila Neves wrote: I benchmarked RefCounted against C++'s std::shared_ptr comparing ldc to clang using both shared and non-shared payloads in D. std::shared_ptr is faster (I've never written a

Re: automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-09 Thread Martin Nowak via Digitalmars-d-announce
On Sunday, 9 April 2017 at 08:56:52 UTC, Atila Neves wrote: I benchmarked RefCounted against C++'s std::shared_ptr comparing ldc to clang using both shared and non-shared payloads in D. std::shared_ptr is faster (I've never written a smart pointer before), but the advantage of non-atomic

automem v0.0.7 - C++ style smart pointers using std.experimental.allocator

2017-04-09 Thread Atila Neves via Digitalmars-d-announce
Using std.experimental.allocator? Tired of writing `scope(exit) allocator.dispose(foo);` in a language with RAII? Me too: http://code.dlang.org/packages/automem Example: I think the code in the README should be enough to understand what's going on. Alpha stuff here but I think the main