1 / 11

Lab2

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];

kalli
Télécharger la présentation

Lab2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

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

More Related