Thread overview
Help with DynamicArray of Emsi Containers
Apr 30, 2022
Christian Köstlin
May 01, 2022
vit
May 01, 2022
Christian Köstlin
April 30, 2022

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.


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:

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:

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

May 01, 2022

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.


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:

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:

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 (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.

May 01, 2022

On 2022-05-01 09:12, vit wrote:

>

DynamicArray has disabled postblit (is not copyable).

Package autoptr is deprecated (internaly redirected to btl:atuoptr), all functionality is moved to package 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.
Thanks a lot for those pointers, I changed/upgraded my dependencies, and it already looks better.