Threads
Problem
Void threadfunc (void *parameters){
Int aMem [1024][1024];
Char *p = “hello”;
Thread body;
}
This is not instantiating thread and exception occurring. What could be the exception
Solution
The stack overflow exception
The default stacksize is 1MB for most of the Os
Array of 1 mb integers will overflow stack size, due to which thread won’t init and raises exception.
Problem: We need to develop a library which can talk to Oracle and Sql server.
Solution:
Factory design pattern.
Use same interface but different implementation for underlying database.
Please post in comment if much more good design pattern available.
Problem: There is a function which will fill the buffer from source to destination and if source is less than destination remaining destination need to be filled with spaces. Now that need to be filled with null values. Or some specific value. This function is all over code base. How do you pass the specific value without changing function usage through code base.
It func (int *ptr, int *dst, int srclen, int dstlen)
Solution:
Change the function like this
Int func ( int *ptr, int*dst, int srclen, int dstlen, int val)
Change the body of the function with val.
Function overloading allow new function change without modify the whole code base. No need to rename the whole code base with function parameter change.
This solution useful for so many occasions.
Problem:
There is an object created and used throught the code base. It has constructor well defined. Now it need to be changed to object pointer instead of object variable throught the code base. For example, class cExClass {
public:
cExClass() { }
~cExClass() { }
void somefunc() { }
}
cExClass oExObj;
oExObj.somefunc();
The above kind of code used everywhere. Now it need to be changed to oExObj->somefunc(), that means you have to create dynbamic memory to the object only. Not object as value. How do you achieve end result without changing entire code base.
Solution:
Create the object with dynamic memory allocation.
cExClass *oExObjp = new cExClass();
cExClass oExObj(*oExObjp);
Careful about copy constructor and assignment operator implementation for the class.
Implement proper destructors.
Int *ptr = new int [1024];For (int I=0; I <1024; I++)
Print (ptr [I+10]);Desired to print all elements from 10th element but bugHow and where.Solution:Always remember to boundary checks for dynamic memory.So it will be
For I= 0; I <1024 -10; I++;
Print (ptr [I+10]);
Problem: How can you find size of structure without using sizeof
Solution
Struct p {
Int I;
Char k;
Struct a b;
};
Simple solution is
Struct p *ptr;
Struct p* qptr;
Struct p* sptr = ptr;
Qptr = ++ptr;
Return qptr – sptr;
Problem:
What is the output of
Char * s = “hello”;
Strcpy (s, s+1);
Solution:
Memory exception in some weak OS.
Windows device driver development WDF
Problem: opening device handle in ioctl. This one will crash the system if properly not used.
Solution:
Open the device handle in the init driver entry point and save it in device context.
In ioctl take the handle from device context and use it for operations.
Std::list <object> oList;
Here by default in some compilers two objects will be created in list. Which cause 2 object constructors will be called by mistake. If the constructor expect to init with memory then exception will come.
Std::vector <object> oVector;
Sometime safe to use.
However design choices can opt anyone of them.
Fixes for problems during configuring Jenkins for Linux as master and Windows as slave node to build
Problem: Unable to git clone repository in Windows Slave node using GIT+SSH.
Solution: Use C:\Program files\Git\Cmd\Git.exe.
Set this as path for environment variable for GIT in Jenkins master while configuring Windows Slave.
Manage Jenkins -> Manage Nodes -> Select Slave -> Configure -> Environment Variables -> Add.
Problem: master rejecting connection that is already connected for Jlnp protocol.
Solution: Goto global configuration settings in master Jenkins. Enable slave to master connectivity.
Problem: Unable to build the sln file using msbuild.
Solution: Jenkins master -> windows batch commands
Goto desired folder where sln located. Using cd
Give complete path to vcvarsall.bat
Give the msbuild file. Sln