本文整理汇总了C++中SharedMemory类的典型用法代码示例。如果您正苦于以下问题:C++ SharedMemory类的具体用法?C++ SharedMemory怎么用?C++ SharedMemory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SharedMemory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: alloc_buffer_size
static SharedMemory* alloc_buffer_size(const char* message, int size)
{
SharedMemory* buffer = new SharedMemory(size);
buffer->map();
memcpy(buffer->data(), message, buffer->size());
return buffer;
}
示例2: file_receive_shm
static SharedMemory* file_receive_shm(int header, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, const char* str)
{
uint32_t tid;
if (monapi_name_whereis("/servers/file", tid) != M_OK) {
return NULL;
}
MessageInfo msg;
if (Message::sendReceive(&msg, tid, header, arg1, arg2, arg3, str) != M_OK) {
return NULL;
}
if ((intptr_t)msg.arg2 < M_OK) {
int status = Message::reply(&msg);
if (status != M_OK) {
monapi_warn("%s reply failed : %s\n", __func__, monapi_error_string(status));
}
return NULL;
}
uintptr_t handle = msg.arg2;
uintptr_t size = msg.arg3;
SharedMemory* shm = new SharedMemory(handle, size);
if (shm->map(true) != M_OK) {
int status = Message::reply(&msg);
delete shm;
if (status != M_OK) {
monapi_warn("%s reply failed : %s\n", __func__, monapi_error_string(status));
}
return NULL;
} else {
int status = Message::reply(&msg);
if (status != M_OK) {
monapi_warn("%s reply failed : %s\n", __func__, monapi_error_string(status));
}
return shm;
}
}
示例3: test_fatfs_readdir
static void test_fatfs_readdir()
{
TestFatFS fs;
FatFileSystem* fat = fs.get();
Vnode* root = fat->getRoot();
SharedMemory* cmi;
ASSERT_EQ(M_OK, fat->read_directory(root, &cmi));
ASSERT_TRUE(cmi != NULL);
int size = *(int*)cmi->data();
EXPECT_EQ(37, size);
monapi_directoryinfo* p = (monapi_directoryinfo*)&cmi->data()[sizeof(int)];
EXPECT_STR_EQ("TEST1.TXT", (const char*)CString(p[0].name));
for (int i = 0; i < size; i++) {
if (CString(p[i].name) == "SUBDIR") {
EXPECT_TRUE((p[i].attr & ATTRIBUTE_DIRECTORY) != 0);
}
}
delete cmi;
}
示例4: HandleReuse
static bool HandleReuse(LPCTSTR lpstrCmdLine)
{
SharedMemory<HWND> sharedInstance;
try
{
sharedInstance.Open(L"ConsoleZ", syncObjNone);
}
catch(Win32Exception& ex)
{
if(ex.GetErrorCode() == ERROR_FILE_NOT_FOUND)
return false;
throw;
}
if (0 != sharedInstance.Get())
{
::SetForegroundWindow(*sharedInstance);
std::wstring commandLine = lpstrCmdLine;
commandLine += L" -cwd ";
commandLine += Helpers::EscapeCommandLineArg(Helpers::GetCurrentDirectory());
COPYDATASTRUCT cds = {0};
cds.dwData = 0;
cds.lpData = (LPVOID)commandLine.c_str();
cds.cbData = static_cast<DWORD>((commandLine.length() + 1) * sizeof(wchar_t));
::SendMessage(*sharedInstance, WM_COPYDATA, 0, (LPARAM)&cds);
return true;
}
return false;
}
示例5: monapi_clipboard_get
SharedMemory* monapi_clipboard_get()
{
uint32_t tid ;
if (monapi_name_whereis("/servers/clipboard", tid) != M_OK) {
return NULL;
}
MessageInfo msg;
if (Message::sendReceive(&msg, tid, MSG_CLIPBOARD_GET) != M_OK) {
return NULL;
}
if ((intptr_t)msg.arg2 < M_OK) { return NULL;}
SharedMemory* ret = new SharedMemory(msg.arg2, msg.arg3);
if (ret->size() == 0) {
return ret;
}
intptr_t mapResult = ret->map(true);
if (mapResult != M_OK) {
delete ret;
monapi_warn("%s map error = %d\n", __func__, mapResult);
return NULL;
} else {
return ret;
}
}
示例6: test_fatfs_write_file
static void test_fatfs_write_file()
{
TestFatFS fs;
FatFileSystem* fat = fs.get();
Vnode* root = fat->getRoot();
const char* FILENAME = "MY1.TXT";
Vnode* found;
ASSERT_EQ(M_OK, fat->lookup(root, FILENAME, &found, Vnode::REGULAR));
const int BUFFER_SIZE = 1029;
SharedMemory* buffer = new SharedMemory(BUFFER_SIZE);
ASSERT_EQ(M_OK, buffer->map());
memset(buffer->data(), 0, BUFFER_SIZE);
buffer->data()[0] = 0xde;
buffer->data()[BUFFER_SIZE - 1] = 0xad;
io::Context c;
c.offset = 0;
c.size = BUFFER_SIZE;
c.memory = buffer;
ASSERT_EQ(BUFFER_SIZE, fat->write(found, &c));
io::Context readContext;
SharedMemory* cmi = readAll(fat, readContext, root, FILENAME);
ASSERT_TRUE(cmi != NULL);
ASSERT_TRUE(cmi->data() != NULL);
ASSERT_EQ(BUFFER_SIZE, cmi->size());
EXPECT_TRUE(memcmp(buffer->data(), cmi->data(), BUFFER_SIZE) == 0);
}
示例7: SharedMemory
void* SharedMemory::get(unsigned int id, unsigned int size){
SharedMemory* newSharedMemory = new SharedMemory();
int sharedMemoryId = getSharedMemoryId(id, size);
newSharedMemory->setId(id);
newSharedMemory->setSharedMemoryId(sharedMemoryId);
return newSharedMemory->attach();
}
示例8: main
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
SharedMemory shared;
shared.read();
return a.exec();
}
示例9: susanKernel
__global__
void susanKernel(T* out, const T* in,
const unsigned idim0, const unsigned idim1,
const unsigned radius, const float t, const float g,
const unsigned edge)
{
const int rSqrd = radius*radius;
const int windLen = 2*radius+1;
const int shrdLen = BLOCK_X + windLen-1;
SharedMemory<T> shared;
T* shrdMem = shared.getPointer();
const unsigned lx = threadIdx.x;
const unsigned ly = threadIdx.y;
const unsigned gx = blockDim.x * blockIdx.x + lx + edge;
const unsigned gy = blockDim.y * blockIdx.y + ly + edge;
const unsigned nucleusIdx = (ly+radius)*shrdLen + lx+radius;
shrdMem[nucleusIdx] = gx<idim0 && gy<idim1 ? in[gy*idim0+gx] : 0;
T m_0 = shrdMem[nucleusIdx];
#pragma unroll
for (int b=ly, gy2=gy; b<shrdLen; b+=BLOCK_Y, gy2+=BLOCK_Y) {
int j = gy2-radius;
#pragma unroll
for (int a=lx, gx2=gx; a<shrdLen; a+=BLOCK_X, gx2+=BLOCK_X) {
int i = gx2-radius;
shrdMem[b*shrdLen+a] = (i<idim0 && j<idim1 ? in[j*idim0+i]: m_0);
}
}
__syncthreads();
if (gx < idim0 - edge && gy < idim1 - edge) {
unsigned idx = gy*idim0 + gx;
float nM = 0.0f;
#pragma unroll
for (int p=0; p<windLen; ++p) {
#pragma unroll
for (int q=0; q<windLen; ++q) {
int i = p - radius;
int j = q - radius;
int a = lx + radius + i;
int b = ly + radius + j;
if (i*i + j*j < rSqrd) {
float c = m_0;
float m = shrdMem[b * shrdLen + a];
float exp_pow = powf((m - c)/t, 6.0f);
float cM = expf(-exp_pow);
nM += cM;
}
}
}
out[idx] = nM < g ? g - nM : T(0);
}
}
示例10: fire
void HecoDSMFinalizer::fire()
{
SharedMemory *mem;
if (!(mem = dynamic_cast<SharedMemory *>(sinkPorts()[0]->readPort()))) {
PERR("Invalid type.");
}
int *num = (int *)mem->buffer();
PINF_1("Num = " << num[0] << " " << num[1] << " " << num[2] <<
" " << num[3]);
_state = POST_RUNNING;
}
示例11: createFile
static void createFile(const char* path)
{
EXPECT_TRUE(!fileExist(path));
intptr_t id = monapi_file_open(path, FILE_CREATE);
const char* message = "Hello World\n";
SharedMemory shm = alloc_buffer(message);
monapi_file_write(id, shm, shm.size());
monapi_file_close(id);
}
示例12: monapi_clipboard_set
intptr_t monapi_clipboard_set(const SharedMemory& shm)
{
MessageInfo msg;
uint32_t tid ;
if (monapi_name_whereis("/servers/clipboard", tid) != M_OK) {
return M_NAME_NOT_FOUND;
}
intptr_t ret = Message::sendReceive(&msg, tid, MSG_CLIPBOARD_SET, shm.handle(), shm.size());
if (ret != M_OK) {
return ret;
}
return M_OK;
}
示例13: LOG_TRACE
ELTE_INT32 SharedMemoryMgr::CreateSharedMemory(const std::string& strResId)
{
LOG_TRACE();
INFO_PARAM1(strResId);
std::map <std::string, SharedMemory*>::iterator iter = m_sharedMemorys.find(strResId);
if(m_sharedMemorys.end() != iter)
{
return eLTE_SDK_ERR_SUCCESS;
}
SharedMemory* pSharedMemory = new SharedMemory(strResId);
if (NULL == pSharedMemory)
{
return eLTE_SDK_ERR_NULL_POINTER;
}
//初始化资源
ELTE_INT32 iRet = pSharedMemory->InitResource();
if(eLTE_SDK_ERR_SUCCESS != iRet)
{
delete pSharedMemory;
pSharedMemory = NULL;
return iRet;//lint !e438
}
//开启接受视频流线程
iRet = pSharedMemory->StartYuvFrameProcess();
if(eLTE_SDK_ERR_SUCCESS != iRet)
{
delete pSharedMemory;
pSharedMemory = NULL;
return iRet;//lint !e438
}
//开启发送视频流线程
iRet = pSharedMemory->StartRevMsg();
if(eLTE_SDK_ERR_SUCCESS != iRet)
{
delete pSharedMemory;
pSharedMemory = NULL;
return iRet;//lint !e438
}
(ELTE_VOID)m_sharedMemorys.insert(std::pair <std::string, SharedMemory*> (strResId, pSharedMemory));
return eLTE_SDK_ERR_SUCCESS;//lint !e429
}
示例14: histogramKernel
static __global__
void histogramKernel(Param<outType> out, CParam<inType> in,
int len, int nbins, float minval, float maxval, int nBBS)
{
SharedMemory<outType> shared;
outType * shrdMem = shared.getPointer();
// offset input and output to account for batch ops
unsigned b2 = blockIdx.x / nBBS;
const inType *iptr = in.ptr + b2 * in.strides[2] + blockIdx.y * in.strides[3];
outType *optr = out.ptr + b2 * out.strides[2] + blockIdx.y * out.strides[3];
int start = (blockIdx.x-b2*nBBS) * THRD_LOAD * blockDim.x + threadIdx.x;
int end = minimum((start + THRD_LOAD * blockDim.x), len);
float step = (maxval-minval) / (float)nbins;
// If nbins > max shared memory allocated, then just use atomicAdd on global memory
bool use_global = nbins > MAX_BINS;
// Skip initializing shared memory
if (!use_global) {
for (int i = threadIdx.x; i < nbins; i += blockDim.x)
shrdMem[i] = 0;
__syncthreads();
}
for (int row = start; row < end; row += blockDim.x) {
int idx = isLinear ? row : ((row % in.dims[0]) + (row / in.dims[0])*in.strides[1]);
int bin = (int)((iptr[idx] - minval) / step);
bin = (bin < 0) ? 0 : bin;
bin = (bin >= nbins) ? (nbins-1) : bin;
if (use_global) {
atomicAdd((optr + bin), 1);
} else {
atomicAdd((shrdMem + bin), 1);
}
}
// No need to write to global if use_global is true
if (!use_global) {
__syncthreads();
for (int i = threadIdx.x; i < nbins; i += blockDim.x) {
atomicAdd((optr + i), shrdMem[i]);
}
}
}
示例15: monapi_call_file_decompress_bz2
SharedMemory* monapi_call_file_decompress_bz2(const SharedMemory& shm)
{
uint32_t tid;
if (monapi_name_whereis("/servers/file", tid) != M_OK) {
return NULL;
}
MessageInfo msg;
if (Message::sendReceive(&msg, tid, MSG_FILE_DECOMPRESS_BZ2, shm.handle(), shm.size()) != M_OK) {
return NULL;
}
if (msg.arg2 == 0) return NULL;
SharedMemory* ret = new SharedMemory(msg.arg2, msg.arg3);
if (ret->map(true) != M_OK) {
delete ret;
return NULL;
} else {
return ret;
}
}