I have this simplified class (many details omitted) :
template<class T, size_t nChunkSize = 1000>
class Holder
{
size_t m_nSize = 0;
size_t m_nChunkSize = nChunkSize;
public:
Holder(size_t nSize)
: m_nSize(nSize)
{
}
size_t GetChunkSize()
{
return m_nChunkSize;
}
T* GetChunk(size_t nChunkIndex)
{
// returns the address of the chunk nChunkIndex
return ###;
}
T& operator[](size_t nIndex)
{
// returns the element with index nIndex
return T();
}
};
The idea is to have a simple memory manager that allocates really large number of objects but if there is not enough memory to hold all objects in one place it splits them in chunks and encapsulates everything. I know I should use STL but I have specific reasons to do it this way.
I want to provide the users the ability to specify the chunk size and be able to get a pointer to a specific chunk but only if they have specified the template parameter otherwise I want that functionality to be disabled at compile time.
I know the compiler should know whether nChunkSize is defaulted or user specified but is there a way I can get that information and use it to delete GetChunk function or make it's usage not compilable.
For example:
Holder<int, 200> intHolder(5000);
intHolder[312] = 2;
int* pChunk = intHolder.GetChunk(3); // OK, Compiles
Holder<int> intAnotherHolder(500);
pChunk = intAnotherHolder(20); // COMPILE ERROR
Aucun commentaire:
Enregistrer un commentaire