Code Monkey home page Code Monkey logo

Comments (5)

Klusxy avatar Klusxy commented on July 28, 2024

reason :

// memory model : x64
struct Node { void* p1; }
FixedObjectPool<Node> pool(3);
// header size (int, int)                     ---- 8 byte
// index 1(uint32), index 2(uint32)   ---- 8 
// index 3(uint32), xxxxx (padding)  ---- 8 
// entry 1 size(void*)                        ---- 8
// entry 2 size(void*)                        ---- 8
// entry 3 size(void*)                        ---- 8

in this func :

ObjectPoolBlock<T>* ObjectPoolBlock<T>::create(index_t entries_per_block)
{
……
// here index size is align to entry size
const size_t indices_size = align_to(sizeof(index_t) * entries_per_block, entry_align);
……
}

// but here, u calc (index_t* + 1), in x64, this is 4byte, but Entry pointer is 8 byte
// so, u should no align index_size or convert index_t* to T*
template <typename T>
index_t* ObjectPoolBlock<T>::indices_begin() const
{
    // calculcates the start of the indicies
    return reinterpret_cast<index_t*>(const_cast<ObjectPoolBlock<T>*>(this + 1));
}

T* ObjectPoolBlock<T>::memory_begin() const
{
……
return reinterpret_cast<T*>(indices_begin() + entries_per_block_);
}

from objectpool.

Klusxy avatar Klusxy commented on July 28, 2024

fix :

ObjectPoolBlock<T>* ObjectPoolBlock<T>::create(index_t entries_per_block)
{
……
const size_t indices_size = align_to(sizeof(index_t) * entries_per_block, sizeof(index_t));
……
}

other fix :

T* ObjectPoolBlock<T>::memory_begin() const
{
	const size_t entry_align = alignof(T);
	const size_t indices_size = align_to(sizeof(index_t) * entries_per_block_, entry_align);
	return reinterpret_cast<T*>(reinterpret_cast<uint8_t*>(indices_begin()) + indices_size);
}

from objectpool.

bitshifter avatar bitshifter commented on July 28, 2024

Thanks for investigating, it might be easier to make a PR if you have a fix :)

from objectpool.

Klusxy avatar Klusxy commented on July 28, 2024

:), has been submitted

from objectpool.

fayce66 avatar fayce66 commented on July 28, 2024

@bigt1234 could you please close that issue if it has been fixed? thanks

from objectpool.

Related Issues (3)

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.