randolf.ca  1.00
Randolf Richardson's C++ classes
Loading...
Searching...
No Matches
rring_blocks
1#pragma once
2
3namespace randolf {
4
5 /*======================================================================*//**
6 @brief
7 Structure of positions and lengths of data blocks in ring buffer memory.
8 This is specifically useful for direct memory access to the ring buffer's
9 memory, which will need to be split into two operations when the buffer
10 straddles the memory boundary.
11
12 @note
13 The following code demonstrates how to access ring buffer memory:
14 @code{.cpp}
15 #include <randolf/rring>
16 #include <randolf/rring_blocks>
17
18 // ... code that initializes a ring buffer and populates it; documentation
19 // for this is available in the @ref rring class ...
20
21 char b1 = 0;
22 char b2 = 0;
23 char a1 = 0;
24 char a2 = 0;
25
26 std::shared_ptr<randolf::rring_blocks> rblk = rb.get_data_blocks();
27
28 if (rblk->block1 != nullptr) // Check for pointer (avoids segfault)
29 b1 = ((char*)rblk->block1)[0]; // First byte of utilized buffer memory
30
31 if (rblk->block2 != nullptr) // Check for pointer (avoids segfault)
32 b2 = ((char*)rblk->block2)[0]; // Second byte of utilized buffer memory
33
34 if (rblk->avail1 != nullptr) // Check for pointer (avoids segfault)
35 a1 = ((char*)rblk->avail1)[0]; // First byte of available buffer memory
36
37 if (rblk->avail2 != nullptr) // Check for pointer (avoids segfault)
38 a2 = ((char*)rblk->avail1)[0]; // Second byte of available buffer memory
39 @endcode
40 @see rring::get_data_blocks
41 @par History
42 - 2024-Dec-03 v1.00 Initial version
43 @version 1.00
44 @author Randolf Richardson
45 *///=========================================================================
46 struct rring_blocks {
47
48 /*======================================================================*//**
49 @brief
50 Pointer to first portion of utilized buffer memory.
51 *///=========================================================================
52 void* block1;
53
54 /*======================================================================*//**
55 @brief
56 Pointer to second portion of utilized buffer memory, if this part of the ring
57 buffer straddles the boundary, otherwise @c nullptr will be specified.
58 *///=========================================================================
59 void* block2;
60
61 /*======================================================================*//**
62 @brief
63 Pointer to first portion of available buffer memory.
64 *///=========================================================================
65 void* avail1;
66
67 /*======================================================================*//**
68 @brief
69 Pointer to second portion of available buffer memory, if this part of the
70 ring buffer straddles the boundary, otherwise @c nullptr will be specified.
71 *///=========================================================================
72 void* avail2;
73
74 /*======================================================================*//**
75 @brief
76 Number of elements in @ref block1.
77 *///=========================================================================
78 size_t block1_size;
79
80 /*======================================================================*//**
81 @brief
82 Number of elements in @ref block2.
83 *///=========================================================================
84 size_t block2_size;
85
86 /*======================================================================*//**
87 @brief
88 Number of elements in @ref avail1.
89 *///=========================================================================
90 size_t avail1_size;
91
92 /*======================================================================*//**
93 @brief
94 Number of elements in @ref avail2.
95 *///=========================================================================
96 size_t avail2_size;
97
98 }; // -x- struct rring_blocks -x-
99
100}; // -x- namespace randolf -x-