Moderators: phlip, Moderators General, Prelates
3fj wrote:It strikes me that whilst delete deallocates memory, it keeps the pointer refrence. Is there a way to forget it?
template<typename T>
void safe_delete(T* &ptr)
{
delete ptr;
ptr = NULL;
}
//Example usage
int* ptr = new int;
*ptr = 5;
safe_delete(ptr); //deletes pointer and sets it to NULL
//ptr is now NULL
sprintf("%d", foo);poxic wrote:You suck. And simultaneously rock. I think you've invented a new state of being.
'; DROP DATABASE;-- wrote:Also:Why does GCC let me do this?
- Code: Select all
sprintf("%d", foo);
'; DROP DATABASE;-- wrote:Also:Why does GCC let me do this?
- Code: Select all
sprintf("%d", foo);
'; DROP DATABASE;-- wrote:Also:Why does GCC let me do this?
- Code: Select all
sprintf("%d", foo);
for(i = 0x80000000; i<0x80400000; i++)
{
request 1 byte starting at i
wait for reply
write reply[0] to file
}request 0x400000 bytes starting at 0x80000000
wait for reply
for(i=0; i<0x400000; i++)
write reply[i] to filepoxic wrote:You suck. And simultaneously rock. I think you've invented a new state of being.
Mm, you'd be surprised how much overhead there is on a one-byte transmission. TCP header, IP header, Ethernet header and footer; and that has to be put on at one end and taken off at the other. I'm surprised you got 11k/s'; DROP DATABASE;-- wrote:You might think with both programs running on the same machine (i.e. connected to localhost), the difference in transfer speeds would be negligible. WRONG!
Method 1: 11 KB/s
Method 2: 27,060 KB/s
int leetness_level = Over9000();
if (leetness_level > 9000) {
// Really leet code omitted
}
MoD wrote:Clearly your school teaches Java in a better fashion than mine. I wrote a program to write the programs they assign.
Its output is typically longer than its source code, if that gives an idea of the programs' typical complexity.
Berengal wrote:Only if they're killer robots. Legos are happy robots. Besides, even if they were killer robots it wouldn't stop me. You can't stop science and all that.
Rysto wrote:I've just been assigned a ticket in our internal bug-tracking system. The due date for the ticket is January 18, 2038. For full marks, answer:
1) What's the bug I have to fix?
2) The due date of this bug is wrong. How is it wrong, and why is it wrong?
Rysto wrote:I've just been assigned a ticket in our internal bug-tracking system. The due date for the ticket is January 18, 2038. For full marks, answer:
1) What's the bug I have to fix?
2) The due date of this bug is wrong. How is it wrong, and why is it wrong?
tetsujin wrote:2: Hmmm... Maybe the application needs to store future dates sometimes? Maybe you need time (more than a day) to test the fix after it's in?
'; DROP DATABASE;-- wrote:I thought I did... guess not.
Also, a lesson in efficiency. I implemented a simple protocol in an N64 emulator to read and write the game's memory over TCP/IP. You send a request containing address, # bytes, and a command (9 bytes in total), and it sends back however many bytes you requested.
As an experiment, I dumped all 4MB using this protocol in two different ways, and measured their speeds. The first method was a simple loop: (pseudocode)
- Code: Select all
for(i = 0x80000000; i<0x80400000; i++)
{
request 1 byte starting at i
wait for reply
write reply[0] to file
}
The second made only a single request:
- Code: Select all
request 0x400000 bytes starting at 0x80000000
wait for reply
for(i=0; i<0x400000; i++)
write reply[i] to file
You might think with both programs running on the same machine (i.e. connected to localhost), the difference in transfer speeds would be negligible. WRONG!
Method 1: 11 KB/s
Method 2: 27,060 KB/s.
Some of us exist to find out what can and can't be done.
Others exist to hold the beer.
typedef long S32;Sandry wrote:Bless you, Briareos.
Blriaraisghaasghoasufdpt.
Oregonaut wrote:Briareos is my new bestest friend.
Posi wrote:That language is VHDL.
Rysto wrote:I just love how everybody has to define their own fixed width types. I just found the following in some code:
- Code: Select all
typedef long S32;
Xanthir wrote:Long isn't necessarily 32 bits?
# cat tmp.c
#include <stdio.h>
int main(int argc, char ** argv)
{
printf("sizeof(long) == %zd\n", sizeof(long));
return 0;
}
# ./a.out
sizeof(long) == 8
char buf[32];
sprintf(buf, "%f", foo);for(j=0; j<32; j++)
{ //8 (size of CPU regs) * 32 (# CPU regs) = 256
CurData[256 + (8 * j)] = (unsigned char)((reg_cop1_fgr_64[j / 2] >> (24 + (j & 1 ? 32 : 0))) & 0xFF);
CurData[257 + (8 * j)] = (unsigned char)((reg_cop1_fgr_64[j / 2] >> (16 + (j & 1 ? 32 : 0))) & 0xFF);
CurData[258 + (8 * j)] = (unsigned char)((reg_cop1_fgr_64[j / 2] >> (8 + (j & 1 ? 32 : 0))) & 0xFF);
CurData[259 + (8 * j)] = (unsigned char)((reg_cop1_fgr_64[j / 2] >> (0 + (j & 1 ? 32 : 0))) & 0xFF);
CurData[260 + (8 * j)] = 0;
CurData[261 + (8 * j)] = 0;
CurData[262 + (8 * j)] = 0;
CurData[263 + (8 * j)] = 0;
}poxic wrote:You suck. And simultaneously rock. I think you've invented a new state of being.
phlip wrote:More than that, though, is that this is a problem that has already been solved...
Ignoring the standard headers and rolling your own typedefs for that sort of thing accomplishes two things:
* Adds one more thing that needs to be changed and tested (and could easily break stuff if you forget to change it) if/when you actually port the code to another platform (such as x86-64).
* Makes the code harder to read, 'cause you're using new names for things that a newcomer to the code might not recognise (and calling it just "S32" only adds to that)... int32_t has a better chance of being recognised by the reader, since, being standard, they have a better chance of having seen it before.
tetsujin wrote:Creating your own typedefs isn't a perfect solution - but just having that typedef there (even if it's not cross-platform correct) means that you can easily fix the code later, by changing the typedef in one place rather than usage in several hundred places.
You, sir, name? wrote:Today's realization is how much speed you can gain by enabling the more... unorthodox compiler flags sacrificing binary compatibility and standards compliance.
Going from
gcc -O2
to
gcc -O3 -march=athlon64 -funroll-all-loops -ffast-math
Made my volumetric buddhabrot generator run 5 times faster. From 20 seconds per frame to 3 seconds per frame. It was like going from MATLAB to C
Posi wrote:I know that a language is not worth learning unless it changes the way you think (or something like that), but this one just makes me think about suicide. That language is VHDL.
For those that don't know about it, VHDL is a hardware describtion language. It allows you to implement hardware in software. A bonus is you do not have to figure out how you would actually have to implement the piece of hardware, but you can use the language to aid you with that. My beef with the language isn't so much about the language (although I do prefer {} over BEGIN END), its more the toolchain my school uses sucks ass in ways I have yet to dream of. What really takes the cake is that the compiler has two error messages: "Line XX: syntax error" and "Line XX: feature YZ is not supported in this implementation". I kinda find it hard to believe that a company made money off of this.
Belial wrote:The sex card is tournament legal. And I am tapping it for, like, six mana.
Users browsing this forum: shealtket and 5 guests