Jump to content

  • Log In with Google      Sign In   
  • Create Account

bradbobak

Member Since 07 Oct 2004
Offline Last Active Today, 02:36 AM

#5187870 Weird if() behavior

Posted by bradbobak on 18 October 2014 - 01:33 PM


for(int i = 1; i < 10; i++)
{
backlog[i] = backlog[i-1];
}

 

fyi, i think this is wrong.. everything will be set to backlog[0]. I think you need to do the loop in reverse.




#5168050 Win32 API, GetMessage() after PeekMessage()

Posted by bradbobak on 20 July 2014 - 08:01 PM

afaik, PM_NOREMOVE causes the PeekMessage() to leave the message on the queue. GetMessage() then removes the message from the queue.

 

edit: although this example would probably be fine with just the PeekMessage() without the PM_NOREMOVE.




#5154707 File Loading Adds Weird Characters to the end

Posted by bradbobak on 19 May 2014 - 05:00 PM

 As far as i know, a text file is treated similar to binary file except that some os's do some linefeed, carriage return translations. Text files are sometimes parsed by reading line-by-line, which, in c++, is straightforward to do (std::getline()). You have the filesize, you know when you've reached the end of file, and you can read line-by-line if you want. Thinking from a text file point of view, i don't even think '\0' is valid in it (does getline() stop at the '\0'). I guess what i'm trying to say, a text file is basically a binary file except it generally contains printable text rather than some sort of binary data and a '\0' would be considered binary data.

 

 (did i get that right, lol) 

 

EDIT: ninja'd




#5154697 File Loading Adds Weird Characters to the end

Posted by bradbobak on 19 May 2014 - 04:17 PM

 You need to add a '\0' c-string terminator. make the char buffer 1 bigger, then when you read it, assign the last char in the array a value of 0. 

 

int filesize = whatever;
char *buf = new char[filesize + 1];
read_the_data();
buf[filesize] = 0;

 

 This is needed as a c-string holds a null terminator to signify the end of the string.




#5154346 Strange "read" and "write" functions in OIS

Posted by bradbobak on 17 May 2014 - 06:45 PM

 read, write, and close are posix functions. 'man 2 read' in unix should bring up the man pages.

 

 From your compiler output it seems like the header files are not being included. Try including <unistd.h>, that may fix your problem.




#5108386 Counting cores and hardware threads

Posted by bradbobak on 10 November 2013 - 07:46 PM

 I read somewhere that the 8 core fx series has 4 'modules' each with 2 integer cores and a shared floating point core per module. so, maybe that has something to do with this.




#5067538 multiple base classes with virtual functions.

Posted by bradbobak on 04 June 2013 - 11:45 PM

B (or A) is not a C so doing 'C *c = new B;' cannot cast a B to a C pointer.

Perhaps you meant to do 'B *b = new C;' ? 




#5067031 some help with command line parsing (got everything to work..sort of)

Posted by bradbobak on 03 June 2013 - 02:16 AM

 You have:

 

char* file = argv[i++];

 

 If the filename is to be supplied after "--Help" perhaps you want '++i'.

 Just as a side note, the strings == is case-sensitive so '--help' wouldn't match.




#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.




PARTNERS