On Saturday, 30 April 2022 at 20:22:43 UTC, Christian Köstlin
wrote:
I am struggling with initializing an Emsi Containers
DynamicArray in a nice way. Some background information of my
usecase:
I experimenting in porting some old 3d engine code of mine from
c++ to dlang. In the engine I want to exactly control when
resources are freed and not rely on the garbage collector. For
that I am using reference counters courtesy of autoptr.
e.g.
```d
alias Texture = IntrusivePtr!TextureData; // dub package autoptr
class TextureData
{
IFImage image; // dub package imagefmt
}
```
another class of mine now is supposed to hold several of those
textures for multitexturing and should be initialized in its
constructor:
```d
class Appearance
{
Texture[] textures;
this(Texture[] textures)
{
this.textures = textures;
}
}
```
Unfortunately this does not work properly together with
autoptr's (see
https://github.com/submada/autoptr/issues/5#issuecomment-997683868).
Because of that I am using now DynamicArrays from Emsi
Containers, but I am having trouble initializing them:
```d
class Apperance
{
DynamicArray!Texture textures;
this(DynamicArray!Texture textures)
{
this.textures = textures;
}
}
```
does not compile.
What would be the best way to initialize the variable?
Kind regards,
Christian
DynamicArray has disabled postblit (is not copyable).
Package autoptr is deprecated (internaly redirected to
btl:atuoptr), all functionality is moved to package
[BTL](https://code.dlang.org/packages/btl) (subpackage
btl:autoptr). This library contains subpackage btl:vector with
functionality like DynamicArray with support for copying. I use
IntrusivePtr inside Vector/SmallVector and i have no problems.