Remove: AutoFreeSmallVector.

The last use was for storing a list of memory blocks. As the way these lists are accessed is very
specific, it is easier to just write an explicit destructor instead of trying to exactly match the behaviour.
This commit is contained in:
Michael Lutz 2019-04-02 21:31:41 +02:00
parent e804173595
commit 8b1880187a
3 changed files with 18 additions and 34 deletions

View File

@ -69,34 +69,4 @@ T* grow(std::vector<T>& vec, std::size_t num)
return vec.data() + pos;
}
/**
* Simple vector template class, with automatic free.
*
* @note There are no asserts in the class so you have
* to care about that you grab an item which is
* inside the list.
*
* @param T The type of the items stored, must be a pointer
*/
template <typename T>
class AutoFreeSmallVector : public std::vector<T> {
public:
~AutoFreeSmallVector()
{
this->Clear();
}
/**
* Remove all items from the list.
*/
inline void Clear()
{
for (T p : *this) {
free(p);
}
std::vector<T>::clear();
}
};
#endif /* SMALLVEC_TYPE_HPP */

View File

@ -42,7 +42,7 @@
struct PacketReader : LoadFilter {
static const size_t CHUNK = 32 * 1024; ///< 32 KiB chunks of memory.
AutoFreeSmallVector<byte *> blocks; ///< Buffer with blocks of allocated memory.
std::vector<byte *> blocks; ///< Buffer with blocks of allocated memory.
byte *buf; ///< Buffer we're going to write to/read from.
byte *bufe; ///< End of the buffer we write to/read from.
byte **block; ///< The block we're reading from/writing to.
@ -54,6 +54,13 @@ struct PacketReader : LoadFilter {
{
}
~PacketReader() override
{
for (auto p : this->blocks) {
free(p);
}
}
/**
* Add a packet to this buffer.
* @param p The packet to add.

View File

@ -126,15 +126,22 @@ struct ReadBuffer {
/** Container for dumping the savegame (quickly) to memory. */
struct MemoryDumper {
AutoFreeSmallVector<byte *> blocks; ///< Buffer with blocks of allocated memory.
byte *buf; ///< Buffer we're going to write to.
byte *bufe; ///< End of the buffer we write to.
std::vector<byte *> blocks; ///< Buffer with blocks of allocated memory.
byte *buf; ///< Buffer we're going to write to.
byte *bufe; ///< End of the buffer we write to.
/** Initialise our variables. */
MemoryDumper() : buf(NULL), bufe(NULL)
{
}
~MemoryDumper()
{
for (auto p : this->blocks) {
free(p);
}
}
/**
* Write a single byte into the dumper.
* @param b The byte to write.