MNN/source/core/FileLoader.hpp

43 lines
907 B
C++
Raw Normal View History

//
// FileLoader.hpp
// MNN
//
// Created by MNN on 2019/07/04.
// Copyright © 2018, Alibaba Group Holding Limited
//
#include <vector>
2021-09-18 15:52:30 +08:00
#include <mutex>
2019-12-27 22:16:57 +08:00
#include "core/AutoStorage.h"
namespace MNN {
class MNN_PUBLIC FileLoader {
public:
FileLoader(const char* file);
~FileLoader();
bool read();
2021-09-18 15:52:30 +08:00
2022-01-04 10:50:40 +08:00
static bool write(const char* filePath, std::pair<const void*, size_t> cacheInfo);
bool valid() const {
return mFile != nullptr;
}
inline size_t size() const {
return mTotalSize;
}
bool merge(AutoStorage<uint8_t>& buffer);
2022-12-30 15:18:58 +08:00
int offset(int64_t offset);
bool read(char* buffer, int64_t size);
private:
std::vector<std::pair<size_t, void*>> mBlocks;
FILE* mFile = nullptr;
static const int gCacheSize = 4096;
size_t mTotalSize = 0;
2021-09-18 15:52:30 +08:00
const char* mFilePath = nullptr;
};
} // namespace MNN