Code Monkey home page Code Monkey logo

Comments (9)

markisus avatar markisus commented on August 25, 2024

Can you elaborate on this? Looking through the code it's not obvious what or where a failure would occur.

from ring-buffer.

jnk0le avatar jnk0le commented on August 25, 2024

Currently insert/removal uses copy constructors everywhere, (i.e. T a = b;) which als means memory leak if T is allocating anything.

from ring-buffer.

markisus avatar markisus commented on August 25, 2024

As I understand, this should work fine if the author of the class has properly implemented the copy assignment operator. For example, if T is std::shared_ptr, the copy assign would first decrement the usage count of the pointer held in a and then increment the usage count of the pointer held in b.

from ring-buffer.

jnk0le avatar jnk0le commented on August 25, 2024

copy assignment

ah, assignment, not constructor.

It will still leak until given slot is reused for new data, not to mention that the buffer array is uninitialized.

I'll add the assert until figuring out the std::move + rval refs and all of the related "what ifs".

from ring-buffer.

markisus avatar markisus commented on August 25, 2024

I think the slot would hold onto memory until reuse, but that’s much better than a leak because the buffer size is bounded.

Anyway thanks for the library!

from ring-buffer.

huweiATgithub avatar huweiATgithub commented on August 25, 2024

The copy assignment a = b is ok if the copy assignment operator of type T is implemented.
It is responsibility of the maintainer of type T to ensure that current resources is freed before copy resources from others.

Is my understand correct?

from ring-buffer.

jnk0le avatar jnk0le commented on August 25, 2024

Currently the buffer array is uninitialized, so that will be very undefined operation.

This would also make the copy constructors unusable for it's intended purpose.

from ring-buffer.

huweiATgithub avatar huweiATgithub commented on August 25, 2024

Currently the buffer array is uninitialized, so that will be very undefined operation.

This would also make the copy constructors unusable for it's intended purpose.

I see. So, if the type can be default constructed, then it will be fine?

from ring-buffer.

jnk0le avatar jnk0le commented on August 25, 2024

As long as all members are also trivially (default) constructible.

from ring-buffer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.