Re: std.expreimantal.allocator deallocate

2021-01-25 Thread vitamin via Digitalmars-d-learn
On Monday, 25 January 2021 at 10:28:11 UTC, Jacob Carlborg wrote: On Sunday, 24 January 2021 at 11:00:17 UTC, vitamin wrote: void destruct(Base base){ void[] x = (cast(void*)base)[0 .. __traits(classInstanceSize, Base)]; writeln("deallocate: ", x.length); theAllocator.deallocate(x

Re: std.expreimantal.allocator deallocate

2021-01-25 Thread Jacob Carlborg via Digitalmars-d-learn
On Sunday, 24 January 2021 at 11:00:17 UTC, vitamin wrote: void destruct(Base base){ void[] x = (cast(void*)base)[0 .. __traits(classInstanceSize, Base)]; writeln("deallocate: ", x.length); theAllocator.deallocate(x); } You can get the dynamic size of an object using `typeid(bas

Re: std.expreimantal.allocator deallocate

2021-01-25 Thread vitamin via Digitalmars-d-learn
On Sunday, 24 January 2021 at 18:38:42 UTC, Petar Kirov [ZombineDev] wrote: On Sunday, 24 January 2021 at 14:56:25 UTC, Paul Backus wrote: [...] To add to that, if an allocator defines `resolveInternalPointer` [0][1] you could be able to get the original slice that was allocated (and then pa

Re: std.expreimantal.allocator deallocate

2021-01-24 Thread Petar via Digitalmars-d-learn
On Sunday, 24 January 2021 at 14:56:25 UTC, Paul Backus wrote: On Sunday, 24 January 2021 at 11:00:17 UTC, vitamin wrote: It is Ok when I call deallocate with smaller slice or I need track exact lengtht? It depends on the specific allocator, but in general, it is only guaranteed to work corre

Re: std.expreimantal.allocator deallocate

2021-01-24 Thread Petar via Digitalmars-d-learn
On Sunday, 24 January 2021 at 16:16:12 UTC, vitamin wrote: On Sunday, 24 January 2021 at 14:56:25 UTC, Paul Backus wrote: On Sunday, 24 January 2021 at 11:00:17 UTC, vitamin wrote: It is Ok when I call deallocate with smaller slice or I need track exact lengtht? It depends on the specific all

Re: std.expreimantal.allocator deallocate

2021-01-24 Thread vitamin via Digitalmars-d-learn
On Sunday, 24 January 2021 at 14:56:25 UTC, Paul Backus wrote: On Sunday, 24 January 2021 at 11:00:17 UTC, vitamin wrote: It is Ok when I call deallocate with smaller slice or I need track exact lengtht? It depends on the specific allocator, but in general, it is only guaranteed to work corre

Re: std.expreimantal.allocator deallocate

2021-01-24 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 24 January 2021 at 11:00:17 UTC, vitamin wrote: It is Ok when I call deallocate with smaller slice or I need track exact lengtht? It depends on the specific allocator, but in general, it is only guaranteed to work correctly if the slice you pass to deallocate is exactly the same as

std.expreimantal.allocator deallocate

2021-01-24 Thread vitamin via Digitalmars-d-learn
Allocators from std.expreimantal.allocator allocate memory and return slice void[] to allocated memory. Method deallocate has as parameter void[] slice to allocated memory. It is Ok when I call deallocate with smaller slice or I need track exact lengtht? Example: import std.experimental.allo