* Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#ifndef FLINK_TNEL_MEMORYSEGMENT_H
#define FLINK_TNEL_MEMORYSEGMENT_H
#include <cstdint>
#include "Segment.h"
* Notice, MemorySegment always wrap the existing mem
*
*/
class MemorySegment : public Segment {
public:
MemorySegment(uint8_t* offHeapBuffer, int size);
explicit MemorySegment(int size);
MemorySegment(uint8_t* offHeapBuffer, int size, void* owner);
uint8_t* getAll();
void* getOwner();
uint8_t get(int index);
uint8_t* getData();
void put(int index, uint8_t b);
void put(int index, const uint8_t* src, int offset, int length);
int getSize() const;
* Writes the given long value (64bit, 8 bytes) to the given position in the system's native
* byte order.
*/
void putLong(int index, long value);
* Reads a long value (64bit, 8 bytes) from the given position, in the system's native byte
* order.
*/
long* getLong(int index);
void putInt(int index, int value);
int* getInt(int index);
* Bulk get method. Copies length memory from the specified position to the destination memory,
* beginning at the given offset.
*/
void get(int index, uint8_t* dst, int offset, int length);
int size();
bool equalTo(MemorySegment seg2, int offset1, int offset2, int length);
~MemorySegment() override;
private:
static const bool cLittleEndian = true;
uint8_t* offHeapBuffer_;
int size_;
void* owner_;
};
#endif