MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / allocate

Method allocate

lite/test/test_network.cpp:23–37  ·  view source on GitHub ↗

allocate memory of size in the given device with the given align

Source from the content-addressed store, hash-verified

21public:
22 //! allocate memory of size in the given device with the given align
23 void* allocate(LiteDeviceType device, int, size_t size, size_t align) override {
24 LITE_ASSERT(device == LiteDeviceType::LITE_CPU);
25 m_nr_left++;
26 m_nr_allocated++;
27#ifdef WIN32
28 return _aligned_malloc(size, align);
29#elif defined(__ANDROID__) || defined(ANDROID) || defined(__OHOS__)
30 return memalign(align, size);
31#else
32 void* ptr = nullptr;
33 auto err = posix_memalign(&ptr, align, size);
34 mgb_assert(!err, "failed to malloc %zubytes with align %zu", size, align);
35 return ptr;
36#endif
37 };
38
39 //! free the memory pointed by ptr in the given device
40 void free(LiteDeviceType device, int, void* ptr) override {

Callers 2

alloc_staticMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected