1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00
tracy/public/common/TracyNameBuffer.hpp
Arnim Balzer 9e4af3aca0
Add name buffer to tracy client library
To be used by Python and Go bindings to store const char * accessible via a lookup
2024-05-04 14:52:32 +01:00

38 lines
743 B
C++

#pragma once
#include <mutex>
#include <optional>
#include <string>
#include <vector>
namespace tracy {
using OptionalNumber = std::optional<uint16_t>;
using BufferEntry = std::pair<OptionalNumber, const char*>;
class NameBuffer {
public:
static inline BufferEntry Add( const std::string& name ) {
return getBuffer().add(name);
}
static inline const char* Get( uint16_t index ) {
return getBuffer().get(index);
}
private:
NameBuffer();
std::mutex m_mutex;
std::vector<char*> m_buffer;
std::size_t m_index;
static inline NameBuffer& getBuffer() {
static NameBuffer buffer;
return buffer;
}
BufferEntry add( const std::string& name );
const char* get( uint16_t index );
};
} // namespace tracy