MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / resize

Method resize

Engine/MemoryFile.cpp:293–331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

291}
292
293void
294MemoryFile::resize(size_t new_size)
295{
296#if defined(__NATRON_UNIX__)
297 if (_imp->data) {
298 if (::munmap(_imp->data, _imp->size) < 0) {
299 std::stringstream ss;
300 ss << "MemoryFile EXC : Failed to unmap \"" << _imp->path << "\": " << std::strerror(errno) << " (" << errno << ")";
301 throw std::runtime_error( ss.str() );
302 }
303 }
304 if (::ftruncate(_imp->file_handle, new_size) < 0) {
305 std::stringstream ss;
306 ss << "MemoryFile EXC : Failed to truncate the file \"" << _imp->path << "\": " << std::strerror(errno) << " (" << errno << ")";
307 throw std::runtime_error( ss.str() );
308 }
309 _imp->data = static_cast<char*>( ::mmap(
310 0, new_size, PROT_READ | PROT_WRITE, MAP_SHARED, _imp->file_handle, 0) );
311 if (_imp->data == MAP_FAILED) {
312 _imp->data = 0;
313 std::stringstream ss;
314 ss << "MemoryFile EXC : Failed to create mapping of \"" << _imp->path << "\": " << std::strerror(errno) << " (" << errno << ")";
315 throw std::runtime_error( ss.str() );
316 }
317
318#elif defined(__NATRON_WIN32__)
319 ::UnmapViewOfFile(_imp->data);
320 ::CloseHandle(_imp->file_mapping_handle);
321 _imp->file_mapping_handle = ::CreateFileMapping(
322 _imp->file_handle, 0, PAGE_READWRITE, 0, new_size, 0);
323 _imp->data = static_cast<char*>( ::MapViewOfFile(
324 _imp->file_mapping_handle, FILE_MAP_WRITE, 0, 0, 0) );
325#endif
326
327 if (!_imp->data) {
328 throw std::bad_alloc();
329 }
330 _imp->size = new_size;
331}
332
333void
334MemoryFilePrivate::closeMapping(bool drop_pages)

Callers 15

copyUtf8ArgsToMembersMethod · 0.45
appendPointMethod · 0.45
setValueMethod · 0.45
setValueMethod · 0.45
setValueMethod · 0.45
setValueMethod · 0.45
getOperatorStringsFunction · 0.45
createGLContextMethod · 0.45
getGPUInfosMethod · 0.45
clearAndResizeMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected