Should I save memory by using byte, short and float?

Our teacher tells us always to use int and double. But what if I don't need such precision or large values?
Shouldn't I use byte, short and float instead?

You don't save any memory if you use floats instead of doubles in a method. These variables only exist on the stack when the method is executing. Also remember that Java may do type conversions from float to double in expressions. This may make your code slower.
If you have a class with large quantities of doubles, for example an array of 100000 doubles, then you may consider using floats, because the memory saving is substantial. If you access the array from outside the class via double methods you can easily do this change local to the class late in the development process.
I'd say generally it's better to do as your teacher says and standardize on doubles and integers. If you write your program well you can always optimize later if you have to.

Similar Messages

  • After I installed the recent Apple security patch, I can no longer save PDFs when using Safari. And Firefox no longer can open website PDFs. Any suggestions?

    After I installed the recent Apple security patch, I can no longer save PDFs when using Safari. And Firefox no longer can open website PDFs. Any suggestions?

    Dansyacht wrote:
    If the previous Safari suggestion doesn't work try the following:
    In Finder, go to Macintosh HD/Library/Internet Plug-ins and move AdobePDFViewerNPAPI.plugin to the Disabled Plug-ins Folder.  Restart Safari.  If this works you may just want to delete that FUBAR plug-in.
    Thanks.  This was the solution for me.
    Message was edited by: tvdowntown

  • How to save .pdf file using office word and excel

    Can someone help me how to save .pdf files using office word and excel?  I reinstalled my adobe 7.0 pro in my new pc and before I was able to do it but with my old pc.

    For anything after Office 2003, you have to print to the Adobe PDF printer. If you installed AA 7 on OS newer than XP, you may have to do a workaround to get it to work. With later versions of WORD you can always use the MS plugin for creating PDFs.

  • Any trick to save as PDF using Windows 7 and Safari 5.1.7?

    Is there a reason I cannot "Save As PDF" using Safari on Windows 7 / PC?  Version is 5.1.7
    Thanks

    You've tried turning off all firewall and antivirus software ? If that doesn't work then you could try downloading the 5.1.1 update via a browser :
    original iPad
    iPad 2 wifi
    iPad 2 gsm/sim
    iPad 2 CDMA
    iPad 2 new
    iPad 3 wifi
    iPad 3 gsm
    iPad 3 CDMA
    When it's finished downloading, in your computer's iTunes press and hold the shift key on Windows (command key on Mac) when clicking the Check For Updates button which should let you navigate to the downloaded file.

  • When to use short and byte

    when do i should really use byte and short anyway?
    let's say i'm writing a MIDlet and i really really want to save up some memory at run time, would it be helpful if i will use short and byte if i dont need large numbers? let's say i only need a maximum representation of 500?
    i know int is commonly used, but is it worth the change?

    I don't know about the Micro Editon VM, but the Java Standard Edition run-time VM has no special instructions for operating using byte primitives as opposed to, say, integer or short primitives, and byte primitives in the VM are stored as ints, I believe. So, chances are your optimizations of these primitives aren't going to save you that much in terms of speed or memory. However, again, my previous comments only apply to the Standard Edition VM [feel free to correct them if I am wrong, as I am not sure if these restrictions have changed since Java v1.3 or not].
    Plus, if your value is going to be a maximum of 500, you need a short because the signed byte primitive will only be valid across the -128 to 127 range.
    -Dok

  • Use always int or short and byte if int is not needed?

    If I have a variable for percentage and if I don't want to use double or float, what type should the variable be? byte? short? int? long?
    Is there a rule? What is a good style?

    The problem is with casting and that it seems that
    Java programmers just use int and double no matter if
    they really need such great values and precision.
    Am I right?You're probably right. I have standardized on int/double, but always use getter/setter methods. In this way I can change the internal representation of variables, for example to save memory space, without affecting the rest of the program. For variables declared in methods I think it's worth using int/double even if you could use "smaller" types. The memory allocated for those variables are reclaimed when the method ends and you don't have to bother much with implicit conversions.

  • Is it wise to keep the Nikon camera files "DSC's"  after downloading them and converting to DNG files via Adobe converter for lightroom use. In other words do the DNG files have all the raw data I would ever need in processing or should I save the camera'

    Is it wise to keep the Nikon camera files "DSC's"  after downloading them and converting to DNG files via Adobe converter for lightroom use. In other words do the DNG files have all the raw data I would ever need in processing or should I save the camera's DSC files?

    DNG files do not contain some metadata supplied by the camera, which can be used by the manufacturer's software. Thus, if you don't keep the original Raw photo, you will lose this information.
    If your 1000% sure you're never going to use the manufacturer's software, then this isn't a problem. But who can be sure what software you will be using 10 years from now?

  • HT201269 I am trying to save memory on my iPhone 4S/ ios6. Can I back up all photos to icloud and the external hard disk I normally use for photos? If I then delete photos from the iPhone do the get deleted on iCloud?

    I am trying to save memory on my iPhone 4S/ ios6.
    1) Can I back up all photos to icloud and the external hard disk I normally use for photos? If I then delete photos from the iPhone do the get deleted on iCloud?
    2) Can I back up the newsstand to iCloud and save memory on the iPhone?
    3) Can I back up the bookshelf to icloud and save memory on the iPhone?

    1. What format is the external drive? It sounds like it's ina format that Macs can't write to. Is it a NAS or NTFS?
    2. Easiest thing: just move your iPhoto Library to the external
    Make sure the drive is formatted Mac OS Extended (Journaled)
    1. Quit iPhoto
    2. Copy the iPhoto Library from your Pictures Folder to the External Disk.
    3. Hold down the option (or alt) key while launching iPhoto. From the resulting menu select 'Choose Library' and navigate to the new location. From that point on this will be the default location of your library.
    4. Test the library and when you're sure all is well, trash the one on your internal HD to free up space.
    Regards
    TD

  • Is there a good website creation app on the iPad, or should I save up and get a MacBook to use RapidWeaver/iWeb?

    Is there a good website creation app on the iPad, or should I save up and get a MacBook to use RapidWeaver/iWeb?

    Wasn't being condescending, this is a new thead that continues one he already started asking if he could get iWeb on the iPad. Two people explained to him that iWeb was being discontinued (along with MobileMe) and suggested Rapidweaver and two other apps as replacements. It was also explained to him that there were no web creation apps on the iPad because you need to run a local web server, such as Apache, on your computer in order to use them. This is why they work on the Mac because it does have such a server. The iPad does not have one and cannot run one. And I suggested using HTML code if he wanted to develop on his iPad.
    You were aware that is how web creation software works?
    Here is the other thread:
    https://discussions.apple.com/message/15804045#15804045
    Do you know a good book on HTML web creation you could recomment to him?
    Message was edited by: deggie
    Message was edited by: deggie

  • To save memory on my Ipad 16gb rather than store films, can I send them to Icloud and use my storage there and simply bring one back when I want to watch.

    To save memory on my Ipad as I only have the 16gb - rather than store films on the ipad, can i send them to icloud and bring back when i want to watch one. Or can I compress them to save memory. I know I should have bought the 32 or 64 gb ???

    You can't send films to iCloud, whether you can re-download them depends upon what country that you are in (films can't currently be re-downloaded in all) and whether the relevant film studios have agreed to allow them to be re-downloaded, and whether they remain in the store (content providers occasionally remove their items). There are a number of wifi-enabled drives that you can buy that allow you to stream films and tv shows to an iPad, so you don't necessarily have to store them on your iPad e.g. Seagate GoFlex Satellite (I haven't got one so I don't know how good they are)

  • Register() and register(byte[], short, byte)

    According to JavaCard 2.2.1 API:
    register()
    -This method is used by the applet to register this applet instance with the Java Card runtime environment and to assign the Java Card platform name of the applet as its instance AID bytes.
    register(byte[], short, byte)
    -This method is used by the applet to register this applet instance with the Java Card runtime environment and assign the specified AID bytes as its instance AID bytes.
    1. As far as I know, the later is used for assigning specific instance AID. But if the register() is used, what is the instance AID?
    2. If I have registered only one instance with JCRE, should I select it by its applet AID or instance AID? Why is it so?
    Thanks!

    upz , sorry maybe my question is not right ,arent ?.. correctly I ask how to configure OCF on my linux, so I can connect my smart card reader , smart card and the host application (that develop with OCF) .
    thank for reply..
    Correctly ,.. I have more question..about applet. For you knowing I am developing smart card as ID and password to access computer application..can you help me ?
    my question :
    if I want to storage ID and password data to smart card memory .. where I must to place these data, so I can update that data on other time..
    do you have some code that similiar with my applet ?
    thank ..

  • When to use byte

    Is it really worth to use primitive datatypes like byte and short over int, when arithmetic is used? I've read that byte and short are converted to int prior to arithmetic and it just seems cumbersome when some of your bytes/shorts mingle with ints. When do people actually use these datatypes other than memory critical apps?
    thanks

    The reason I ask is because I have some values that fit within a byte and so I thought it best to use the smallest appropriate data type, but at times working with byte has proven to be a pain so I was thinking of just moving most of my bytes to ints. I was more just concerned with the impact on memory.

  • Problem using byte indexed pixel format in setPixels method of PixelWriter

    I try to construct a byte array and set it to a WritableImage using PixelWriter's setPixels method.
    If I use an RGB pixel format, it works. If I use a byte-indexed pixel format, I get an NPE.
    The stride etc should be fine if I'm not mistaken.
    java.lang.NullPointerException
         at com.sun.javafx.image.impl.BaseByteToByteConverter.<init>(BaseByteToByteConverter.java:45)
         at com.sun.javafx.image.impl.General$ByteToByteGeneralConverter.<init>(General.java:69)
         at com.sun.javafx.image.impl.General.create(General.java:44)
         at com.sun.javafx.image.PixelUtils.getB2BConverter(PixelUtils.java:223)
         at com.sun.prism.Image$ByteAccess.setPixels(Image.java:770)
         at com.sun.prism.Image.setPixels(Image.java:606)
         at javafx.scene.image.WritableImage$2.setPixels(WritableImage.java:199)
    Short, self-contained example here:
    import java.nio.ByteBuffer;
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.image.ImageView;
    import javafx.scene.image.PixelFormat;
    import javafx.scene.image.WritableImage;
    import javafx.scene.layout.BorderPane;
    import javafx.stage.Stage;
    public class IndexedColorTestApp extends Application {
        public static void main(String[] args) {
            launch(args);
        @Override
        public void start(Stage primaryStage) {
            BorderPane borderPane = new BorderPane();
            Scene scene = new Scene(borderPane, 600, 1100);
            primaryStage.setScene(scene);
            ImageView imageView = new ImageView();
            borderPane.setCenter(imageView);
            primaryStage.show();
            int imageWidth = 200;
            int imageHeight = 200;
            WritableImage writableImage = new WritableImage(imageWidth, imageHeight);
            // this works
            byte[] rgbBytePixels = new byte[imageWidth * imageHeight * 3];
            PixelFormat<ByteBuffer> byteRgbFormat = PixelFormat.getByteRgbInstance();
            writableImage.getPixelWriter().setPixels(0, 0, imageWidth, imageHeight,
                                                     byteRgbFormat, rgbBytePixels, 0, imageWidth * 3);
            imageView.setImage(writableImage);
            // this throws an NPE in setPixels()
            byte[] indexedBytePixels = new byte[imageWidth * imageHeight];
            int[] colorPalette = new int[256];
            PixelFormat<ByteBuffer> byteIndexedFormat = PixelFormat.createByteIndexedInstance(colorPalette);
            writableImage.getPixelWriter().setPixels(0, 0, imageWidth, imageHeight,
                                                     byteIndexedFormat, indexedBytePixels, 0, imageWidth);
            imageView.setImage(writableImage);
    }If there's no solution, maybe someone knows a workaround? We chose to use indexed format because of data size / performance reasons.
    Edited by: Andipa on 01.03.2013 10:52

    You have found a platform bug, file it against the Runtime project at => http://javafx-jira.kenai.com with your sample code and a link back to this forum question.
    Byte indexed pixel formats seem like a feature which was never completely (or perhaps even hardly at all) implemented to me.
    The PixelFormat type your failed case is using is (PixelFormat.Type.BYTE_INDEXED):
    PixelFormat<ByteBuffer> byteIndexedFormat = PixelFormat.createByteIndexedInstance(colorPalette);
    System.out.println(byteIndexedFormat.getType());These are the valid PixelFormat types =>
    http://docs.oracle.com/javafx/2/api/javafx/scene/image/PixelFormat.Type.html
    BYTE_BGRA
    The pixels are stored in adjacent bytes with the non-premultiplied components stored in order of increasing index: blue, green, red, alpha.
    BYTE_BGRA_PRE
    The pixels are stored in adjacent bytes with the premultiplied components stored in order of increasing index: blue, green, red, alpha.
    BYTE_INDEXED
    The pixel colors are referenced by byte indices stored in the pixel array, with the byte interpreted as an unsigned index into a list of colors provided by the PixelFormat object.
    BYTE_RGB
    The opaque pixels are stored in adjacent bytes with the color components stored in order of increasing index: red, green, blue.
    INT_ARGB
    The pixels are stored in 32-bit integers with the non-premultiplied components stored in order, from MSb to LSb: alpha, red, green, blue.
    INT_ARGB_PRE
    The pixels are stored in 32-bit integers with the premultiplied components stored in order, from MSb to LSb: alpha, red, green, blue.As the native pixel format for a WritableImage is not the same as the pixel format you are using, the JavaFX platform needs to do a conversion by reading the pixels in one format and writing them in another format. To do this it must be able to determine a PixelGetter for your PixelFormat (the PixelGetter is an internal thing, not public API).
    And here is the source the determines the PixelGetter for a given PixelFormat type:
    http://hg.openjdk.java.net/openjfx/8/master/rt/file/06afa65a1aa3/javafx-ui-common/src/com/sun/javafx/image/PixelUtils.java
    119     public static <T extends Buffer> PixelGetter<T> getGetter(PixelFormat<T> pf) {
    120         switch (pf.getType()) {
    121             case BYTE_BGRA:
    122                 return (PixelGetter<T>) ByteBgra.getter;
    123             case BYTE_BGRA_PRE:
    124                 return (PixelGetter<T>) ByteBgraPre.getter;
    125             case INT_ARGB:
    126                 return (PixelGetter<T>) IntArgb.getter;
    127             case INT_ARGB_PRE:
    128                 return (PixelGetter<T>) IntArgbPre.getter;
    129             case BYTE_RGB:
    130                 return (PixelGetter<T>) ByteRgb.getter;
    131         }
    132         return null;
    133     }As you can see, the BYTE_INDEXED format is not handled and null is returned instead . . . this is the source of your NullPointerException.

  • Content of message deleted to save memory, where to set?

    Hi,
    When trying to display "Message Content" in the Message Monitoring in the Runtie Workbench do I get the message
    "Content of message deleted to save memory"
    Can anyone tell me where the settings/parameters are for this deletion of message content?
    Stephan

    Hi all,
    I'm just adding this because I think the result of the answers is maybe still not what would be expected by the average XI user :
    ( all explanations are done for a sync SOAP receiver example )
    -Changing settings in the XI integration engine configuration only affects the SXMB_MONI view ( not the adapter(s) view via RWB )
    -Setting the messaging parameter in the Visual admin indeed results in seeing the payload in the RWB adapter engine but...it basically shows the same as the integration engine SXMB_MONI ! In other words, it is apparently showing the internal XI incoming message that hits the soap receiver adapter and NOT the plain soap/http text outgoing request
    ( not what I would want by default )
    -Since an adapter -- by definition -- adapts a message , you should ask yourself which message you want to see ( adapter incoming or adapter outgoing message ) , but I think that in general, you would want to to see the 'raw' outgoing message for an receiver adapter or the 'raw' incoming message message for a sender adapter. ( as the adapter transformed results are visible in the integration engine )
    In my experience, the results regarding this are mixed for several adapters : for the RNIF adapter you see the raw messages but apparently for soap not...
    -the SOAP FAQ note gives the ( only ? ) workaround : add a network listener in between that captures the raw XI outgoing message
    ( with a simple to use java listener attached to the note )
    Hope this helps future users
    regards
    Dirk

  • Nasty memory leak using sockets inside threads

    In short, any time I create or use a socket inside a worker thread, that Thread object instance will never be garbage collected. The socket does not need to be connected or bound, it doesn't matter whether I close the socket or not, and it doesn't matter whether I create the Socket object inside the thread or not. As I said, it's nasty.
    I initially encountered this memory leak using httpclient (which creates a worker thread for every connect() call), but it is very easy to reproduce with a small amount of stand-alone code. I'm running this test on Windows, and I encounter this memory leak using the latest 1.5 and 1.6 JDK's. I'm using the NetBeans 5.5 profiler to verify which objects are not being freed.
    Here's how to reproduce it with an unbound socket created inside a worker thread:
    public class Test {
         public static class TestRun extends Thread {
              public void run() {
                   new Socket();
         public static void main(String[] strArgs) throws Exception {
              for(;;) {
                   (new TestRun()).start();
                   Thread.sleep(10);
    }Here's how to reproduce it with a socket created outside the thread and used inside the worker thread:
    public class Test {
         public static class TestRun extends Thread {
              Socket s;
              public TestRun(Socket s) { this.s = s; }
              public void run() {
                   try {
                        s.bind(new InetSocketAddress(0));
                        s.close();
                   } catch(Exception e) {}
         public static void main(String[] strArgs) throws Exception {
              for(;;) {
                   (new TestRun(new Socket())).start();
                   Thread.sleep(10);
    }Here's how to reproduce it implementing Runnable instead of extending Thread:
    public class Test {
         public static class TestRun implements Runnable {
              public void run() {
                   Socket s = new Socket();
                   try { s.close(); } catch(Exception e) {}
         public static void main(String[] strArgs) throws Exception {
              for(;;) {
                   (new Thread(new TestRun())).start();
                   Thread.sleep(10);
    }I've played with this a lot, and no matter what I do the Thread instance leaks if I create/use a socket inside it. The Socket instance gets cleaned up properly, as well as the TestRun instance when it's implementing Runnable, but the Thread instance never gets cleaned up. I can't see anything that would be holding a reference to it, so I can only imagine it's a problem with the JVM.
    Please let me know if you can help me out with this,
    Sean

    Find out what is being leaked. In the sample programs, add something like this:
        static int loop_count;
            while (true) {
                if (++count >= 1000) {
              System.gc();
              Thread.sleep(500); // In case gc is async
              System.gc();
              Thread.sleep(500);
              System.exit(0);
            }Then run with java -Xrunhprof:heap=sites YourProgram
    At program exit you get the file java.hprof.txt which contains something like this towards the end of the file:
              percent          live          alloc'ed  stack class
    rank   self  accum     bytes objs     bytes  objs trace name
        1  0.47%  0.47%       736    5       736     5 300036 char[]
        2  0.39%  0.87%       616    3       616     3 300000 java.lang.Thread
        3  0.30%  1.17%       472    2       472     2 300011 java.lang.ThreadLocal$ThreadLocalMap$Entry[]
        4  0.27%  1.43%       416    2       416     2 300225 java.net.InetAddress$Cache$Type[]See, only three live Thread objects (the JVM allocates a few threads internally, plus there is the thread running main()). No leak there. Your application probably has some type of object that it's retaining. Look at "live bytes" and "live objs" to see where your memory is going. The "stack trace" column refers to the "TRACE nnnnn"'s earlier in the file, look at those to see where the leaked objects are allocated.
    Other quickies to track allocation:
    Print stats at program exit:
    java -Xaprof YourProgram
    If your JDK comes with the demo "heapViewer.dll" (or
    heapViewer.so or whatever dynamic libraries are called on your system):
    java -agentpath:"c:\Program Files\Java\jdk1.6.0\demo\jvmti\heapViewer\lib\heapViewer.dll" YourProgram
    Will print out statistics at program exit or when you hit Control-\ (Unix) or Control-Break (Windows).

Maybe you are looking for

  • Screen resolution in Java

    Hi, I am trying to determine the current resolution om my monitor. I remember there was a function waaaaaay back when I programmed with Borland C++, which was getWidth, or getScreenWidth... how can I get the screen resolution in Java? Does anyone kno

  • My macbook keeps on freezing with black screen

    My Macbookpro keeps on freezing. Suddenly the screen goes black and it does not respond to any command.

  • Pairing iPhone 3GS with iPad 2

    I thank all of you for the post related to Iphone and Ipad tethering. But, I'm wondering why the iPhone cannot be paired with the iPad using Bluetooth without turning on the Personal Hotspot? If this is possible, please, help me doing it, if not Appl

  • No user and group in console of OBIEE 11g

    Hi, I'm facing a problem in OBIEE 11g, after I login the console, in security realms, there is no user and group in it, all services has been started, and it prompt following message: This page is not available because the necessary security provider

  • Struck In Installing Oracle eSSO Kiosk Manager!

    Hello guys, I am digging my head while installing Oracle eSSO Kiosk Manager(v-go passlogix Signon Manager). I downloaded the software ESSO bundle from OTN and started the installation as per the notes.In the Kiosk Manager Installation ,setup PDF whic