New answers tagged

0

This is not how actual C code is compiled. In reality, the variable u never has a real storage location allocated to it. Instead, the compiler stores the values 2 and 7 on the stack and calls f1. f1 performs its calculation by accessing them at locations relative to the base pointer (a register in the processor, called "ebp" on x86 machines). It then ...


1

If you can't do dynamic allocation, you must statically allocate all possible ImageImpl instances that could be returned by FontImpl::GetImage and return a pointer to one of those based on the parameter that gets passed in. For example: static ImageImpl image_a; static ImageImpl image_b; : static ImageImpl image_z; Image* FontImpl::GetImage(char c){ ...


2

The main question over whether you should implement IDisposable is if you are using any unmanged resources. From the IDisposable Documentation The primary use of this interface is to release unmanaged resources. The garbage collector automatically releases the memory allocated to a managed object when that object is no longer used. However, it is not ...


4

If TestProcedure contains exclusively managed objects (as opposed to the resources such as database connections, GDI+ objects, etc.), there is nothing you need to do. Just create a new instance of TestProcedure at the beginning of the test, and let Garbage Collector handle the removal of the object when the test finishes. If TestProcedure uses objects which ...


6

I'm not going to debug your code, there's not enough context to do this anyway, but I'm going to show you an idiom that you will probably find easier to use correctly. As a bonus, it will also be faster. Have a look at your loop body. You are allocating memory during each iteration and free it under certain circumstances depending on the overall control ...


-1

Apart from the other reasons which were mentioned: If you have measure data, be it pressures, flows, currents, voltages or whatever, this is often done with hardware having an ADC. An ADC typically has 10 or 12 bits, 14 or 16 bits ones are rarer. But let's stick on the 16 bit one - if measuring around full scale, you have an accuracy of 1/65535. That means ...


4

It seems other answers missed one important point: The SIMD architectures can process less/more data depending if they operate on double or float structs (for example, eight float values at a time, or four double values at a time). Performance considerations summary float may be faster on certain CPUs (for example, certain mobile devices). float uses less ...


33

Atomic operations In addition to what others have already said, a Java-specific disadvantage of double (and long) is that assignments to 64-bit primitive types are not guaranteed to be atomic. From the Java Language Specification, Java SE 8 Edition, page 660 (emphasis added): 17.7 Non-atomic Treatment of double and long For the purposes of the ...


46

Backwards Compatibility This is the number one reason for keeping behavior in an already existing language/library/ISA/etc. Consider what would happen if they took floats out of Java. Libgdx (and thousands of other libraries and programs) wouldn't work. It's going to take a lot of effort to get everything updated, quite possibly years for many projects ...


56

Floats use half as much memory as doubles. They may have less precision than doubles, but many applications don't require precision. They have a larger range than any similarly-sized fixed point format. Therefore, they fill a niche that needs wide ranges of numbers but does not need high precision, and where memory usage is important. I've used them for ...


163

LibGDX is a framework mostly used for game development. In game development you usually have to do a whole lot of number crunching in real-time and any performance you can get matters. That's why game developers usually use float whenever float precision is good enough. The size of the FPU registers in the CPU is not the only thing you need to consider in ...



Top 50 recent answers are included