2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
#ifndef __UTIL_VECTOR_H__
|
|
|
|
|
#define __UTIL_VECTOR_H__
|
|
|
|
|
|
2015-06-28 11:18:48 +02:00
|
|
|
#include <cstring>
|
2011-04-27 11:58:34 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "util/aligned_malloc.h"
|
|
|
|
|
#include "util/guarded_allocator.h"
|
2013-06-22 14:35:09 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
2019-08-17 00:54:22 +10:00
|
|
|
/* Own subclass-ed version of std::vector. Subclass is needed because:
|
2015-02-14 18:03:39 +05:00
|
|
|
*
|
2016-02-07 03:40:41 +05:00
|
|
|
* - Use own allocator which keeps track of used/peak memory.
|
2015-02-14 18:03:39 +05:00
|
|
|
* - Have method to ensure capacity is re-set to 0.
|
|
|
|
|
*/
|
2016-02-07 03:40:41 +05:00
|
|
|
template<typename value_type, typename allocator_type = GuardedAllocator<value_type>>
|
2015-06-26 22:36:31 +02:00
|
|
|
class vector : public std::vector<value_type, allocator_type> {
|
2015-02-14 18:03:39 +05:00
|
|
|
public:
|
2018-11-09 11:37:56 +01:00
|
|
|
typedef std::vector<value_type, allocator_type> BaseClass;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-09 11:44:33 +01:00
|
|
|
/* Inherit all constructors from base class. */
|
|
|
|
|
using BaseClass::vector;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-09 11:46:09 +01:00
|
|
|
/* Try as hard as possible to use zero memory. */
|
2018-11-09 12:01:38 +01:00
|
|
|
void free_memory()
|
2015-06-26 22:36:31 +02:00
|
|
|
{
|
2021-05-19 00:55:22 +02:00
|
|
|
vector<value_type, allocator_type> empty;
|
|
|
|
|
BaseClass::swap(empty);
|
2015-02-14 20:49:20 +05:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-14 18:03:39 +05:00
|
|
|
/* Some external API might demand working with std::vector. */
|
|
|
|
|
operator std::vector<value_type>()
|
|
|
|
|
{
|
2016-02-16 13:37:05 +01:00
|
|
|
return std::vector<value_type>(this->begin(), this->end());
|
2015-02-14 18:03:39 +05:00
|
|
|
}
|
|
|
|
|
};
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
|
|
#endif /* __UTIL_VECTOR_H__ */
|