lab2

Click here to load reader

Upload: kalli

Post on 05-Jan-2016

25 views

Category:

Documents


0 download

DESCRIPTION

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]; - PowerPoint PPT Presentation

TRANSCRIPT

Slide 1

TA: Yi Cui01/29/2013Lab2Part 1 Problemschar* ptr;strcpy(ptr, abcdefgh);int *a;*a = 1;void f(int *a){ *a = 1;}

int *a;f(a);LPDWORD bytes;ReadFile(, bytes, )Part 1 Problemschar *buf = new char[128];printf(Size of buf: %d\n, sizeof(buf));CommandCC *pComCC;CommandCC comCC;sizeof(pComCC)? sizeof(comCC)?sizeof(CommandCC)?char *buf = new char[BUF_SIZE];ReadFile(, buf, sizeof(buf), );ReadFile(, buf, strlen(buf), );Part 1 Problems Memory leaksCommandCC *comCC = new CommandCC();char *buf = new char[BUF_SIZE];Error checkingWindows API (CreateFile, ReadFile, WriteFile)CC status codePart 1 ProblemsTedious functionsReduced functionsCreateCCPipe();WriteToCC();ReadCCResponse();CreateRobotPipe();WriteToRobot();ReadRobotResponse();CreatePipe();WriteToPipe();ReadPipeResponse();

Part 1 ProblemsC style functionsC++ classCreatePipe();WriteToPipe();ReadPipeResponse();Have a hard time passing parameters

class Pipe{Handle hPipe;char *buf;int dataSize;int bufSize;Create();Write();Read();};Part 1 ProblemsWhy not do PeekNamedPipe first?ReadFile is blockingBlock your program until finish readingDeadlock is possible PeekNamedPipe is non-blockingReturn immediatelyPipe is possibly not readyParallel graph searchCommunication between processesGraph search technics BFSDFSbFSA*Multiple threadsPart 2GoalsPractice graph search algorithmsBFSDFSbFSA*DifficultiesRead robot response (check Lab1 slides)Parse response bufferPart 2 Program styleBFSSearch();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 ) breakN = G.getNeighbors (t) for each y in N if ( D.find (y) == false ) U.add (y) D.add (y)}Q&A