Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

bradbobak

Member Since 07 Oct 2004
Offline Last Active Today, 01:17 AM
-----

#5025653 Making a Static Lib in Linux

Posted by bradbobak on 25 January 2013 - 09:33 PM

Try "-L../libsophia/build -lsophia" (without the quotes).




#4998346 VS 2012 iostream syntax error!

Posted by bradbobak on 06 November 2012 - 11:08 PM

Maybe you forgot a ';' in the file you include right before iostream.


#4987565 C++ -- Undinitialized Variables

Posted by bradbobak on 06 October 2012 - 08:46 PM

Maybe throw an assert in checking that cellPosition < CELLS_IN_GRID.


#4959191 C++

Posted by bradbobak on 14 July 2012 - 11:20 PM

If you have something like
 Object *Array[4]; 

 Array[4] = new Object[5];

You would be using memory outside of Array (Array[4] is one past the end).

If you have
 std::vector< Object * > Array(4, 0);
 Array[4] = new Object[5];

You would again be using memory outside the array.

Otherwise if you have the first and do assign to a Array[X] where X is in bounds, all the other Array elements remain unchanged.


#4943257 OS and application interaction questions

Posted by bradbobak on 25 May 2012 - 09:07 AM

But how does the Scheduler actually interrupt the application when it has full control?
Is there a timer that interrupts the CPU every 10ms unless it is reset, triggering some Scheduler code?


On x86, you can set up a timer interrupt to trigger every so often.

Does the OS before launching a new thread set the CPU to operate in "user mode" limiting some instructions?


On x86, most os's will set the 'ring level' to 3, limiting some cpu commands (like loading the page table, 'hlt' ing the cpu, etc., making some io ports unavailable)


How does the application allocate memory without hazard, through the memory controller?


Generally, it sends a 'syscall' irq, where when the os recieves it, it maps some memory for the application, possibly adding a page table entry.

How can the OS restrict the application to its own address space, user mode, can't the application disable "user mode" itself?


On x86, the 'kernel' sets the process to ring level 3, limiting many commands. Restricting the address space is basically done by the kernel setting up a unique page table for the process itself before handing over control to the process.

www.osdev.net may have documentation that will help you out.


#4936199 c++ syntax challenge!

Posted by bradbobak on 30 April 2012 - 04:22 PM

I tihnk that because it is a static member function, its treated like a standalone function so you just use a standard non-member function pointer.


struct x
{
 void (*func)();

 static void my_func() { }
};

int main()
{
 x xx;

 xx.func = x::my_func;

  xx.func();
}



#4906348 #pragma once not working?

Posted by bradbobak on 26 January 2012 - 01:44 AM

header guards (or pragma once) just make sure that the header file is read one time per tu (translation unit). so if a.cpp includes it, and b.cpp includes it, and you compile a.cpp and b.cpp separately, there will be 2 instances of 'LogicContainer logic'. Simplest solution is to put 'extern LogicContainer logic' in the header file, and define 'LogicContainer logic' in some .cpp that will be linked in.


#4902262 c++ : Deleting object (not just its pointer) from vector

Posted by bradbobak on 13 January 2012 - 02:12 AM

You are putting copies of a particle object on the vector. This copy will be destructed within vector::erase(). If you have allocated pointers in the particle object itself, its up to you to delete them.


#4900216 Win32 disable or get around key repeating (only check if up or down once)

Posted by bradbobak on 05 January 2012 - 09:31 PM

Take a look at what WM_KEYDOWN sends (in lParam). Microsofts site says there is a bit telling if this is a key repeated or not.


#4896747 Reading pixels from bmp

Posted by bradbobak on 23 December 2011 - 01:41 AM

...    int i = 0;
void *pixel = malloc(size);
while(feof(f) == 0)
{
i++;
fread(&pixel,sizeof(pixel),1,f);
cout << (int)pixel << endl;
};
...


You are telling fread to read into the location of the pointer variable itself. sizeof(pixel) is (probably) 4 or 8, so you are reading that many bytes each iteration.

Perhaps you want to do a 'int num_read = fread(pixel, 1, size, f);' instead of the loop. (you said each pixel is 8 bits).








#4894446 Saving File Help

Posted by bradbobak on 16 December 2011 - 04:38 AM

You cannot concatenate c-strings and integers in that way.

One way to do it  is:

   std::stringstream ss;

   ss << "Level/Chunk" << loop1 << "_" << loop2;

  std::ofstream file(ss.str().c_str());



PARTNERS