CARLA
Loading...
Searching...
No Matches
BufferPool.h
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
9#include "carla/Buffer.h"
10
11#if defined(__clang__)
12# pragma clang diagnostic push
13# pragma clang diagnostic ignored "-Wold-style-cast"
14#endif
16#if defined(__clang__)
17# pragma clang diagnostic pop
18#endif
19
20#include <memory>
21
22namespace carla {
23 /// A pool of Buffer. Buffers popped from this pool automatically return to
24 /// the pool on destruction so the allocated memory can be reused.
25 ///
26 /// @warning Buffers adjust their size only by growing, they never shrink
27 /// unless explicitly cleared. The allocated memory is only deleted when this
28 /// pool is destroyed.
29 class BufferPool : public std::enable_shared_from_this<BufferPool> {
30 public:
31
32 BufferPool() = default;
33
34 explicit BufferPool(size_t estimated_size) : _queue(estimated_size) {}
35
36 /// Pop a Buffer from the queue, creates a new one if the queue is empty.
38 Buffer item;
39 _queue.try_dequeue(item); // we don't care if it fails.
40#if __cplusplus >= 201703L // C++17
41 item._parent_pool = weak_from_this();
42#else
43 item._parent_pool = shared_from_this();
44#endif
45 return item;
46 }
47
48 private:
49
50 friend class Buffer;
51
52 void Push(Buffer &&buffer) {
53 _queue.enqueue(std::move(buffer));
54 }
55
57 };
58
59} // namespace carla
A pool of Buffer.
Definition BufferPool.h:29
Buffer Pop()
Pop a Buffer from the queue, creates a new one if the queue is empty.
Definition BufferPool.h:37
BufferPool(size_t estimated_size)
Definition BufferPool.h:34
BufferPool()=default
void Push(Buffer &&buffer)
Definition BufferPool.h:52
moodycamel::ConcurrentQueue< Buffer > _queue
Definition BufferPool.h:56
A piece of raw data.
std::weak_ptr< BufferPool > _parent_pool
This file contains definitions of common data structures used in traffic manager.