What are smart pointers? What do they solve and what problems do they introduce?
Write C++ code that allocates memory on the stack to a specified alignment.
FooStringAllocator is a multi-threaded string allocator that can be called concurrently. Fix any threading problems with FooStringAllocator with as minimal overhead as possible.
// A thread locking mechanism much like a critical section
struct FooThreadLock
{
// Lock will block until any other
// thread that has called lock calls
// Unlock
void Lock();
void Unlock();
};
struct FooString
{
FooString()
: pString( nullptr )
{}
char* pString;
FooThreadLock lock;
};
void FooStringAllocator( FooString* fooString, size_t strLength )
{
if( !fooString->pString )
{
fooString->lock.Lock();
fooString->pString = new char[strLength];
fooString->lock.Unlock();
}
}++*(unsigned int*)&FooBar;int blobArray[32];
FooBar* pFooBar = new(blobArray + 16) FooBar();
delete pFooBar;struct foo
{
short a;
int b;
int c;
short d;
};
struct bar
{
int a;
int b;
short c;
short d;
};A bullet is shot at the head of a zombie. Assuming constant velocity of the bullet and a stationary target, write a function to determine if the zombie’s head, represented by a sphere, will be hit.
You have been tasked with determining the resilience of a fridge. You are given 2 refrigerators and a 36 story building to test from. We want to know at what floor the refrigerator can be thrown from without breaking. Assuming the refrigerator either shatters or survives with no damage when thrown from a window what is the maximum number of floors you must test?
Propose, in a few sentences, a tool for automatically generating “cover node” data for a level. The cover node specifies a spot where AI can take cover from incoming fire, while being able to fire back. A level should contain numerous cover nodes in advantageous positions. The cover node definition consists of:
Struct CoverNode
{
Struct AngleRange
{
Float minHeading;
Float maxHeading;
};
AngleRange coveredAngles;
AngleRange returnFireAngles;
Bool crouchingCoverOnly;
Bool canFireOverhead;
};The input to this automated tool is two triangle-soup style meshes. One represents the solid level geometry, or collision that stops bullets. The other is the “navmesh,” a 2D representation of the navigable area of the level. AI can stand anywhere within any of the navmesh triangles, and can’t reach any area not covered by navmesh.