Files
TheRock/rocm-systems/projects/rocprofiler-systems/external/dyninst/dataflowAPI/rose/util/AllocatingBuffer.h
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

91 lines
2.9 KiB
C++

// WARNING: Changes to this file must be contributed back to Sawyer or else they will
// be clobbered by the next update from Sawyer. The Sawyer repository is at
// https://github.com/matzke1/sawyer.
#ifndef Sawyer_AllocatingBuffer_H
#define Sawyer_AllocatingBuffer_H
#include "Buffer.h"
#include "Sawyer.h"
#include <dyncompat/lexical_cast.hpp>
#include <cstring> // memcpy
#include <string>
#include <vector>
namespace Sawyer {
namespace Container {
/** Allocates memory as needed.
*
* Allocates as many elements as requested and manages the storage. There is no requirement that the elements be contiguous
* in memory, although this implementation does it that way. */
template<class A, class T>
class AllocatingBuffer: public Buffer<A, T> {
public:
typedef A Address; /** Type of addresses used to index the stored data. */
typedef T Value; /** Type of data that is stored. */
private:
Address size_;
std::vector<Value> values_;
protected:
AllocatingBuffer(Address size): size_(size), values_(size) {}
public:
/** Allocating constructor.
*
* Allocates a new buffer of the specified size. The values in the buffer are default-constructed, and deleted when this
* buffer is deleted. */
static typename Buffer<A, T>::Ptr instance(Address size) {
return typename Buffer<A, T>::Ptr(new AllocatingBuffer(size));
}
typename Buffer<A, T>::Ptr copy() const /*override*/ {
typename Buffer<A, T>::Ptr newBuffer = instance(this->size());
Address nWritten = newBuffer->write(&values_[0], 0, this->size());
if (nWritten != this->size()) {
throw std::runtime_error("AllocatingBuffer::copy() failed after copying " +
dyncompat::lexical_cast<std::string>(nWritten) + " of " +
dyncompat::lexical_cast<std::string>(this->size()) +
(1==this->size()?" value":" values"));
}
return newBuffer;
}
Address available(Address start) const /*override*/ {
return start < size_ ? size_-start : 0;
}
void resize(Address newSize) /*override*/ {
values_.resize(newSize);
}
Address read(Value *buf, Address address, Address n) const /*override*/ {
n = std::min(n, available(address));
if (buf && n>0)
memcpy(buf, &values_[address], n*sizeof(values_[0]));
return n;
}
Address write(const Value *buf, Address address, Address n) /*override*/ {
n = std::min(n, available(address));
if (buf && n>0)
memcpy(&values_[address], buf, n*sizeof(values_[0]));
return n;
}
const Value* data() const /*override*/ {
return size_ > 0 ? &values_[0] : NULL;
}
};
} // namespace
} // namespace
#endif