110 likes | 241 Views
Lab2. TA: Yi Cui 01/29/2013. Part 1 Problems. char* ptr ; strcpy ( ptr , “ abcdefgh ”);. int *a; *a = 1;. void f( int *a) { *a = 1; } int *a; f(a);. LPDWORD bytes; ReadFile (…, bytes, …). Part 1 Problems. char * buf = new char[128];
E N D
Lab2 TA: Yi Cui 01/29/2013
Part 1 Problems char* ptr; strcpy(ptr, “abcdefgh”); int *a; *a = 1; void f(int *a) { *a = 1; } int *a; f(a); LPDWORD bytes; ReadFile(…, bytes, …)
Part 1 Problems char *buf = new char[128]; printf(“Size of buf: %d\n”, sizeof(buf)); CommandCC *pComCC; CommandCCcomCC; sizeof(pComCC)? sizeof(comCC)? sizeof(CommandCC)? char *buf = new char[BUF_SIZE]; ReadFile(…, buf, sizeof(buf), …); ReadFile(…, buf, strlen(buf), …);
Part 1 Problems • Memory leaks • CommandCC *comCC = new CommandCC(); • char *buf = new char[BUF_SIZE]; • Error checking • Windows API (CreateFile, ReadFile, WriteFile) • CC status code
Part 1 Problems Tedious functions Reduced functions CreateCCPipe(…); WriteToCC(…); ReadCCResponse(…); CreateRobotPipe(); WriteToRobot(…); ReadRobotResponse(…); CreatePipe(…); WriteToPipe(…); ReadPipeResponse(…);
Part 1 Problems C style functions C++ class CreatePipe(…); WriteToPipe(…); ReadPipeResponse(…); Have a hard time passing parameters class Pipe { Handle hPipe; char *buf; intdataSize; intbufSize; Create(); Write(); Read(); };
Part 1 Problems • Why not do PeekNamedPipe first? • ReadFile is blocking • Block your program until finish reading • Deadlock is possible • PeekNamedPipe is non-blocking • Return immediately • Pipe is possibly not ready
Parallel graph search • Communication between processes • Graph search technics • BFS • DFS • bFS • A* • Multiple threads
Part 2 • Goals • Practice graph search algorithms • BFS • DFS • bFS • A* • Difficulties • Read robot response (check Lab1 slides) • Parse response buffer
Part 2 Program style • BFSSearch(); • DFSSearch(); • bFSSearch(); • AstarSearch(); if (type == BFS) BFSSearch(); else if (type == DFS) DFSSearch(); …… Search() { U.add (s, 0); D.add (s); while ( U.notEmpty () ) t = U.removeNextTuple () if ( t.ID == T ) break N = G.getNeighbors (t) for each y in N if ( D.find (y) == false ) U.add(y) D.add (y) }