Skip to main content
Spelling, grammar, headings
Source Link
Toby Speight
  • 88.4k
  • 14
  • 104
  • 327

##Comment on testing

Comment on testing

If you are not going to bother with deletedelete then you may as well write a much simpler version.

##Code Review

Code Review

You should mark youyour move operatorconstructor as noexcept.

    pool(pool&& o)  // Why is this not noexcept here.noexcept;

The standard way to implement this is using swap()swap(). See my implementation above. This handles situations like this in a safe way.

Should this not be char*.? The calloperator offsetof() returns the offset in bytes. The char by definition fits into 1 byte, thus a char* is a 1 byte addressable range. Also the standard has special properties for char* that other integer types don't have.

##Comments on testing code.

Comments on testing code

You could use placement new-new to make them more similar. But personally I would override the new/delete operatornew and delete operators so that it usesthey use your pool.

You are forcing a move of all the iterators in the vector. Rather than erasing it, just free the memory and set the pointer to nullptrnullptr. That would be a much better test.

You should use exactly the same code for both tests. The only difference should be the allocator used. You should have one test that uses your custom allocator. While the second test uses an allocator that simply calls newnew/deletedelete underneath the hood.

##Comment on testing

If you are not going to bother with delete then you may as well write a much simpler version.

##Code Review

You should mark you move operator as noexcept.

    pool(pool&& o)  // Why is this not noexcept here.

The standard way to implement this is using swap(). See my implementation above. This handles situations like this in a safe way.

Should this not be char*. The call offsetof() returns the offset in bytes. The char by definition fits into 1 byte, thus a char* is a 1 byte addressable range. Also the standard has special properties for char* that other integer types don't have.

##Comments on testing code.

You could use placement new to make them more similar. But personally I would override the new/delete operator so that it uses your pool.

You are forcing a move of all the iterators in the vector. Rather than erasing it just free the memory and set the pointer to nullptr. That would be a much better test.

You should use exactly the same code for both tests. The only difference should be the allocator used. You should have one test that uses your custom allocator. While the second test uses an allocator that simply calls new/delete underneath the hood.

Comment on testing

If you are not going to bother with delete then you may as well write a much simpler version.

Code Review

You should mark your move constructor as noexcept.

    pool(pool&& o) noexcept;

The standard way to implement this is using swap(). See my implementation above. This handles situations like this in a safe way.

Should this not be char*? The operator offsetof() returns the offset in bytes. The char by definition fits into 1 byte, thus a char* is a 1 byte addressable range. Also the standard has special properties for char* that other integer types don't have.

Comments on testing code

You could use placement-new to make them more similar. But personally I would override the new and delete operators so that they use your pool.

You are forcing a move of all the iterators in the vector. Rather than erasing it, just free the memory and set the pointer to nullptr. That would be a much better test.

You should use exactly the same code for both tests. The only difference should be the allocator used. You should have one test that uses your custom allocator. While the second test uses an allocator that simply calls new/delete underneath the hood.

##Comment on testing If

If you are not going to bother with delete then you may as well write a much simpler version.

They should be noexcept anywayanyway; good to let the language police that for you (it terminates if it actually throws). Also it can help if you were to use your pool with standard libraries as it enables some optimizations.

Otherwise youryou are testing the memory manager code. Which is very complex and will give you different results (because memory has all readyalready been messed with in a previous test).

That is way totoo small a test.

Both of these allocators will finish in the blink of an eye. You want a test that lastlasts a couple of seconds to get real information.

##Comment on testing If you are not going to bother with delete then you may as well write a much simpler version.

They should be noexcept anyway good to let the language police that for you (it terminates if it actually throws). Also it can help if you were to use your pool with standard libraries as it enables some optimizations.

Otherwise your are testing the memory manager code. Which is very complex and will give you different results (because memory has all ready been messed with in a previous test).

That is way to small a test.

Both of these allocators will finish in the blink of an eye. You want a test that last a couple of seconds to get real information.

##Comment on testing

If you are not going to bother with delete then you may as well write a much simpler version.

They should be noexcept anyway; good to let the language police that for you (it terminates if it actually throws). Also it can help if you were to use your pool with standard libraries as it enables some optimizations.

Otherwise you are testing the memory manager code. Which is very complex and will give you different results (because memory has already been messed with in a previous test).

That is way too small a test.

Both of these allocators will finish in the blink of an eye. You want a test that lasts a couple of seconds to get real information.

added 29 characters in body
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341

You should mark you move operator as no-thrownoexcept.

    pool(pool&& o)  // Why is this not nothrownoexcept here.

They should be no-thrownoexcept anyway good to let the language putpolice that extra testing in for you (it terminates if it actually throws). Also it can help if you were to use your pool with standard libraries as it enables some optimizations.

You should mark you move operator as no-throw.

    pool(pool&& o)  // Why is this not nothrow here.

They should be no-throw anyway good to let the language put that extra testing in for you. Also it can help if you were to use your pool with standard libraries as it enables some optimizations.

You should mark you move operator as noexcept.

    pool(pool&& o)  // Why is this not noexcept here.

They should be noexcept anyway good to let the language police that for you (it terminates if it actually throws). Also it can help if you were to use your pool with standard libraries as it enables some optimizations.

Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
Loading