Download
slide1 n.
Skip this Video
Loading SlideShow in 5 Seconds..
Lab2 PowerPoint Presentation

Lab2

115 Views Download Presentation
Download Presentation

Lab2

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Lab2 TA: Yi Cui 01/29/2013

  2. 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, …)

  3. 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), …);

  4. 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

  5. Part 1 Problems Tedious functions Reduced functions CreateCCPipe(…); WriteToCC(…); ReadCCResponse(…); CreateRobotPipe(); WriteToRobot(…); ReadRobotResponse(…); CreatePipe(…); WriteToPipe(…); ReadPipeResponse(…);

  6. 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(); };

  7. 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

  8. Parallel graph search • Communication between processes • Graph search technics • BFS • DFS • bFS • A* • Multiple threads

  9. Part 2 • Goals • Practice graph search algorithms • BFS • DFS • bFS • A* • Difficulties • Read robot response (check Lab1 slides) • Parse response buffer

  10. 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) }

  11. Q&A