diff options
author | Colin Snover | 2016-12-31 19:48:30 -0600 |
---|---|---|
committer | Colin Snover | 2017-01-08 13:20:23 -0600 |
commit | 640f6039ca48f7119478acd6dd66b8ad36bf0753 (patch) | |
tree | d093e4cc1746b0cb91cf4e76409262376d9c2dea /test/cxxtest/sample | |
parent | ff1c2295ab7fdcc5e759f7c0a14ea395677fbf02 (diff) | |
download | scummvm-rg350-640f6039ca48f7119478acd6dd66b8ad36bf0753.tar.gz scummvm-rg350-640f6039ca48f7119478acd6dd66b8ad36bf0753.tar.bz2 scummvm-rg350-640f6039ca48f7119478acd6dd66b8ad36bf0753.zip |
COMMON: Add Span to common library
Span is roughly modelled on the GSL span<T> type, and is intended
to replace direct access to raw pointers -- especially pointers
that are passed to functions along with a separate size
parameter. It provides low-cost bounds-checked reads and writes,
as well as convenience functions for reading common values
(integers of varying endianness, strings, etc.). While similar to
MemoryReadStream in purpose, Span is superior in cases where
memory is writable, where memory is accessed randomly rather than
sequentially, or where any invalid access should be treated as an
unrecoverable error. It should also be more efficient than a
MemoryReadStream because it is implemented using CRTP, so there is
no runtime overhead from dynamic dispatch.
NamedSpan is an extension of Span which provides enhanced
debugging information when out-of-bounds memory accesses occur.
It allows programmers to name the memory span at construction time,
and it also tracks the offsets of subspans so that the absolute
byte offset of the original memory can be provided in the error
message if an out-of-bounds access occurs.
SpanOwner is similar to ScopedPtr but has awareness of the design
of Span objects, so allows the memory pointed to by the Span object
inside the SpanOwner to be freed when the SpanOwner is freed
without requiring holding a separate pointer to the start of
memory. It also provides some copy semantics, so unlike a ScopedPtr,
SpanOwners can be held by objects in movable containers like
Common::Array -- but note that because there are no move semantics
in C++98, this means that a new, complete memory copy of the
pointed-to data will be created, rather than just a new Span
pointing to the same block of memory, when a container holding a
SpanOwner expands.
Diffstat (limited to 'test/cxxtest/sample')
0 files changed, 0 insertions, 0 deletions