CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
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
15
#include <
third-party/moodycamel/ConcurrentQueue.h
>
16
#if defined(__clang__)
17
# pragma clang diagnostic pop
18
#endif
19
20
#include <memory>
21
22
namespace
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.
37
Buffer
Pop
() {
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
56
moodycamel::ConcurrentQueue<Buffer>
_queue
;
57
};
58
59
}
// namespace carla
ConcurrentQueue.h
Buffer.h
carla::BufferPool::Pop
Buffer Pop()
Pop a Buffer from the queue, creates a new one if the queue is empty.
Definition
BufferPool.h:37
carla::BufferPool::BufferPool
BufferPool(size_t estimated_size)
Definition
BufferPool.h:34
carla::BufferPool::BufferPool
BufferPool()=default
carla::BufferPool::Buffer
friend class Buffer
Definition
BufferPool.h:50
carla::BufferPool::Push
void Push(Buffer &&buffer)
Definition
BufferPool.h:52
carla::BufferPool::_queue
moodycamel::ConcurrentQueue< Buffer > _queue
Definition
BufferPool.h:56
carla::Buffer::_parent_pool
std::weak_ptr< BufferPool > _parent_pool
Definition
carla/Buffer.h:366
moodycamel::ConcurrentQueue
Definition
ConcurrentQueue.h:696
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
Generated by
1.18.0