MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / sharedMemoryCreate

Function sharedMemoryCreate

Common/helper_multiprocess.cpp:32–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30#include <string>
31
32int sharedMemoryCreate(const char *name, size_t sz, sharedMemoryInfo *info) {
33#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
34 info->size = sz;
35 info->shmHandle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,
36 PAGE_READWRITE, 0, (DWORD)sz, name);
37 if (info->shmHandle == 0) {
38 return GetLastError();
39 }
40
41 info->addr = MapViewOfFile(info->shmHandle, FILE_MAP_ALL_ACCESS, 0, 0, sz);
42 if (info->addr == NULL) {
43 return GetLastError();
44 }
45
46 return 0;
47#else
48 int status = 0;
49
50 info->size = sz;
51
52 info->shmFd = shm_open(name, O_RDWR | O_CREAT, 0777);
53 if (info->shmFd < 0) {
54 return errno;
55 }
56
57 status = ftruncate(info->shmFd, sz);
58 if (status != 0) {
59 return status;
60 }
61
62 info->addr = mmap(0, sz, PROT_READ | PROT_WRITE, MAP_SHARED, info->shmFd, 0);
63 if (info->addr == NULL) {
64 return errno;
65 }
66
67 return 0;
68#endif
69}
70
71int sharedMemoryOpen(const char *name, size_t sz, sharedMemoryInfo *info) {
72#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)

Callers 1

parentProcessFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected