| 130 | TF_Buffer* TF_NewBuffer() { return new TF_Buffer{nullptr, 0, nullptr}; } |
| 131 | |
| 132 | TF_Buffer* TF_NewBufferFromString(const void* proto, size_t proto_len) { |
| 133 | void* copy = tensorflow::port::Malloc(proto_len); |
| 134 | memcpy(copy, proto, proto_len); |
| 135 | |
| 136 | TF_Buffer* buf = new TF_Buffer; |
| 137 | buf->data = copy; |
| 138 | buf->length = proto_len; |
| 139 | buf->data_deallocator = [](void* data, size_t length) { |
| 140 | tensorflow::port::Free(data); |
| 141 | }; |
| 142 | return buf; |
| 143 | } |
| 144 | |
| 145 | void TF_DeleteBuffer(TF_Buffer* buffer) { |
| 146 | if (buffer == nullptr) return; |