当前位置: 首页>>代码示例>>C++>>正文


C++ SharedMemory类代码示例

本文整理汇总了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;
}
开发者ID:ckkashyap,项目名称:mona,代码行数:7,代码来源:clipboard.cpp

示例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;
    }
}
开发者ID:Nirlendu,项目名称:mona,代码行数:35,代码来源:messages.cpp

示例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;
}
开发者ID:ShotaroTsuji,项目名称:mona,代码行数:25,代码来源:file.cpp

示例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;
}
开发者ID:gaeeronimo,项目名称:console,代码行数:33,代码来源:Console.cpp

示例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;
    }
}
开发者ID:Nirlendu,项目名称:mona,代码行数:25,代码来源:messages.cpp

示例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);
}
开发者ID:ShotaroTsuji,项目名称:mona,代码行数:32,代码来源:file.cpp

示例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();
}
开发者ID:jsaico,项目名称:ProductorConsumidorNM,代码行数:7,代码来源:SharedMemory.cpp

示例8: main

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    SharedMemory shared;
    shared.read();

    return a.exec();
}
开发者ID:yca,项目名称:embedded-ipc,代码行数:9,代码来源:main.cpp

示例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);
    }
}
开发者ID:rotorliu,项目名称:arrayfire,代码行数:56,代码来源:susan.hpp

示例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;
}
开发者ID:freesamael,项目名称:wolf,代码行数:11,代码来源:HecoDSMFinalizer.cpp

示例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);
}
开发者ID:ShotaroTsuji,项目名称:mona,代码行数:12,代码来源:ram_disk.cpp

示例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;
}
开发者ID:Nirlendu,项目名称:mona,代码行数:13,代码来源:messages.cpp

示例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
}
开发者ID:eSDK,项目名称:esdk_elte,代码行数:47,代码来源:SharedMemoryMgr.cpp

示例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]);
        }
    }
}
开发者ID:AshwinRajendraprasad,项目名称:arrayfire,代码行数:47,代码来源:histogram.hpp

示例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;
    }
}
开发者ID:Nirlendu,项目名称:mona,代码行数:20,代码来源:messages.cpp


注:本文中的SharedMemory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。