Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void WriteStackToBuf(Stack *stack, char *pBuf) {
- CopyMemory((void*) (pBuf+sizeof(int)*0),&stack->max_len, sizeof(int));
- CopyMemory((void*) (pBuf+sizeof(int)*1),&stack->top, sizeof(int));
- CopyMemory((void*) (pBuf+sizeof(int)*2),&stack->buf, sizeof(int));
- for(int i=0;i<stack->max_len;i++){
- CopyMemory((void*) (pBuf+sizeof(int)*3+i),&stack->stack[i], sizeof(char));
- }
- }
- Stack ReadStackFromBuf(char *pBuf) {
- int max_len,top,buf;
- Stack s;
- CopyMemory((void*)&max_len,pBuf+sizeof(int)*0, sizeof(int));
- CopyMemory((void*)&top, pBuf+sizeof(int)*1,sizeof(int));
- CopyMemory((void*)&buf,pBuf+sizeof(int)*2, sizeof(int));
- s.max_len=max_len;
- s.top=top;
- s.buf=buf;
- char* stack=new char[max_len];
- for(int i=0;i<max_len;i++){
- CopyMemory((void*)&stack[i],pBuf+sizeof(int)*3+i,sizeof(char));
- }
- s.stack=stack;
- return s;
- }
- int _tmain(int argc, _TCHAR* argv[]) {
- HANDLE hEventBufEmpty=CreateEvent(NULL, FALSE, TRUE, _T("Global\\BufEmpty"));
- HANDLE hEventBufFull=CreateEvent(NULL, FALSE, FALSE, _T("Global\\BufFull"));
- Stack stack;
- HANDLE hMapFile = CreateFileMapping(
- INVALID_HANDLE_VALUE, // use paging file
- NULL, // default security
- PAGE_READWRITE, // read/write access
- 0, // maximum object size (high-order DWORD)
- BUF_SIZE, // maximum object size (low-order DWORD)
- FileInMemoryName); // name of mapping object
- char* pBuf;
- for(;;){
- WaitForSingleObject(hEventBufFull, INFINITE);
- std::cout<<"ASDASD";
- pBuf = (char*) MapViewOfFile(hMapFile, // handle to map object
- FILE_MAP_ALL_ACCESS, // read/write permission
- 0,
- 0,
- BUF_SIZE);
- stack=ReadStackFromBuf(pBuf);
- push(&stack,stack.buf);
- pBuf = (char*) MapViewOfFile(hMapFile, // handle to map object
- FILE_MAP_ALL_ACCESS, // read/write permission
- 0,
- 0,
- BUF_SIZE);
- WriteStackToBuf(&stack,pBuf);
- SetEvent(hEventBufEmpty);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement