2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 02:50:24 +01:00
|
|
|
* limitations under the License.
|
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 <cassert>
|
|
|
|
|
#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"
|
|
|
|
|
#include "util/types.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__ */
|