About Strings and Memory

Let's look at a couple of examples of how a String might be created, and let's further assume that no other String objects exist in the "String constant pool"l:
String s = "abc"; //   creates one String object and one
                  //   reference variable In this simple case, "abc" will go in the pool and s will refer to it.
   String s = new String("abc"); // creates two objects,
                              // and one reference variable In this case, because we used the new keyword, Java will create a new String object
in normal (nonpool) memory, and s will refer to it. In addition, the literal "abc" will
be placed in the pool.
My question is this:
Then why did the sun developers created the 'public String(String str)' constructor even it uses an additional memory?

Caarmel wrote:
Let's look at a couple of examples of how a String might be created, and let's further assume that no other String objects exist in the "String constant pool"l:
String s = "abc"; //   creates one String object and one
//   reference variable In this simple case, "abc" will go in the pool and s will refer to it.Nope. Executing that line only assigns a reference to an already existing String into the variable. The constant was put into the pool when the class was loaded. So your initial assumption of no Strings in the constant pool is invalid.
   String s = new String("abc"); // creates two objects,
// and one reference variable Nope. As above, it creates one object. The other already existed.
Then why did the sun developers created the 'public String(String str)' constructor even it uses an additional memory?First, note that your question really has nothing at all to do with the constant pool. Your question is really "Why does the String(String) constructor exist, given that String is immutable, and given that we can just do s2 = s1?" That question applies even in complete absence of the constant pool.
I wasn't there when they made the decision, so I can't tell you what their thinking was. I can tell you one case where it's useful, however.
String s1 = some_very_long_string;
String s2 = s1.substring(x, x + a_small_number);
String s3 = new String(s1.substring(x, x + a_small_number);Both the s2 and s3 lines create new String objects. However, in the case of s2, the new object shares the same char array as the original, whereas in the s3 case, a new backing array of just the right size is created. If s1 is very large, AND if the substring we're extracting is very small, AND if the substring needs to live on significantly longer than the original, then without the explicit new String(), even though we only need a few characters and could get away with a very small char array, we end up stuck with a large char array that can't be GCed even when the original String is.
So in this rather unlikely scenario, we can avoid wasting a bunch of memory that can't be GCed when we only need a small fraction of it.
Or maybe the constructor came about in early versions, before other aspects of the language making it mostly useless were solidified, and then it was kept for backward compatibility.
Or maybe they didn't really have a good reason and just figured it made sense to have a copy constructor.
Or maybe the reasons that make it mostly redundant are implementation details, and they wanted to provide a copy constructor so that as Java evolved, if the implementation changed, the functionality would still be there.
Or maybe none of the above.

Similar Messages

  • About FCE and memory

    i have a powermac G5 1.8 GHz with a dual processor.
    i recently bought more memory for it (2 GB) because i do a lot of video work in FC. This is the first time using final cut since ive added more memory to my machine and i am trying to render a very simple and short clip in FC but i keep getting:
    "Warning: Insufficient disk space for render. Please free up space and retry."
    this is what i got before and why i bought more memory! I installed the memory myself and it seems to have been done correctly.(it shows me how much memory i now have when i go to "about this mac".)
    can someone please suggest what i might be doing wrong?
    thanks

    The message is about disk space, not memory (RAM). FCE (like many applications) needs hard drive space to work, both for temporary working area as well as to store render files.
    What is the size of your hard drive(s) and how much space is used on each?
    Generally, you should not let a hard drive(s) get more than about 80-85% full. Beyond that you are subject to all kinds of problems, especially if it's your system drive. So, if you have a 250 GB drive, you shouldn't let it get more than about 200-210GB full. I suspect that's why you're getting the error message.

  • MDNSResponder keeps taking up more memory. After restart, it takes up about 5MBs of memory; after a few days, it is currently at 165MBs, and that's not the highest its gone. Currently running 10.5.8 with all updates.

    I'm running an Intel Core Duo iMac with 10.5.8 and all updates.
    The computer has been running slow, even after replacing the HDD a few months ago. I noticed last week in Activity Monitor that the process mDNSResponder was consuming several hundred MBs of memory. I searched, thinking it was malware, but found that it is the correct spelling of the process and is vital for Mac networking. I restarted the computer, and mDNSResponder shrunk to only consuming about 4MBs of memory.
    I checked again a week later, and it's climbed back up to consuming 165MBs of memory, and seems to be climbing.
    Is this normal? Between it and Safari, there's always at least 300MBs of memory being consumed, just being connected and using the internet.
    I've read elsewhere that sometimes Brother printer drivers can cause mDNSResponder to consume much of the CPU; however, I don't have a Brother printer, and mDNSResponder isn't using any of the CPU currently. I couldn't find anything posted about a possible memory leak.
    When I open the process in Activity Monitor, it says there are zero hangs.

    The amount of memory it's using is largely irrelevant - at least given the available data.
    One of the things mDNSresponder does is cache DNS records, so of course it's going to use less memory after a restart (it has no cached data) than it is after a couple of weeks of runtime (it's cached a slew of lookups). In fact, generally you want this process to use memory since it improves overall performance.
    The exception to that rule, of course, is if you don't have enough memory in your machine to do the other tasks, in which case that 165MB might be better used by other processes to reduce paging, but that isn't apparent from your post since you don't include any kind of memory stats. If you have plenty of memory available then the 165MB used by mDNSResponder isn't an issue.
    Look more closely at your memory utilization and processes that have high CPU usage rather that ones with large memory footprints per se.

  • About a JTree of mixed String and JLabel leafs

    Dear Java and Swing freaks,
    Why do I get the text code instead of the expected JLabel in the leaves of my JTree ?
    I want to construct a Jtree in which each tree leaf is made of a JLabel (displaying an amount and with a coloured background), followed by a normal String (the label of this amount).
    An array (of arrays) of Ojects describes the tree that I want to display in a Swing JPanel of Container, as in the "2.1 Simple JTREE Example" at URL
    http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JTree.html
    So, using the "DefaultMutableTreeNode" class and a "private DefaultMutableTreeNode processHierarchy(Object[] hierarchy)" re-entering function.
    Either the 'nodeSpecifier' is of type 'new Object[]', and the 'processHierarchy()' interpretes it as a new node,
    Or the 'nodeSpecifier' is of type 'JLabel' (or 'String'), and the 'processHierarchy()' has to interprete it as a new leaf.
    Of course, 'JLabel', as 'String', is also a subclass of 'Object'.
            BigDecimal TotalDistrNetBeh1= 1.11;
            Object[] hi�rarchie =
            { "Blablabla",
              new Object[]
              { "Bloc de compteurs",
                new Object[] { "Total1" + " : The 1st listed item = The title of this node",
                                     new JLabel(TotalDistrNetBeh1.toPlainString()),
                       /* + "DistrNetBeh1" */
                                     new JLabel(" 2.22")
                       /* + "DistrNetBeh2" */
                new Object[] { "Total2" + " : Title of this node",
                                     new JLabel("Total Bijdrage Herniewbare energie"),
                   /* Test : Leaf of type 'String' mixed with leaves of type 'JLabel'.
                                     "Total Opties : French and Dutch",
                                     "<html>Total Bijdrage <font color=red>WarmteKrachtKoppeling</font></html>",
                                     TotalDistrNetBeh1.toPlainString() + "Test1",
                                     new JLabel("<html>Total <font color=blue>Test2</font></html>")
            };In the displayed tree, rows with JPanel appear like this :
    javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text= 2.22,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    <b>instead of simply " 2.22"</b>, as if there is a hiden (java.lang.String) casting. Why ?
    Nevertheless, the 'nodeSpecifier' argument in
            else
              child = new DefaultMutableTreeNode(nodeSpecifier); // Leafis casted to (javax.swing.JLabel)
    and 'child' and 'node' - both of 'Object' type - seem to be casted to (javax.swing.tree.DefaultMutableTreeNode)
    For memo :
        private DefaultMutableTreeNode constructHi�rarch(Object[] hi�rarchie)
        { DefaultMutableTreeNode node = new DefaultMutableTreeNode(hi�rarchie[0]);
          DefaultMutableTreeNode child;
          for(int i=1; i<hi�rarchie.length; i++)
          { Object nodeSpecifier = hi�rarchie;
    if (nodeSpecifier instanceof Object[]) // Node with children
    // Re-entering the function
    child = constructHi�rarch((Object[])nodeSpecifier);
    else
    child = new DefaultMutableTreeNode(nodeSpecifier); // Leaf
    node.add(child);
    return(node);
    Is it "DefaultMutableTreeNode(nodeSpecifier)" or "add(child)" that cannot operate properly with a argument of type 'JLabel' ?
    How to solve it ?
    Sorry, I'm a beginner in Java and Swing.
    Thanks in advance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Learn to properly use a TreeCellRenderer
    You never need to add a Component to a JTree, ie JLabel. You add the data, like a String, and then render the component you want to appear. Already, the String you have in your JTree are being rendered using JLabels, with a White Background. Hence, you need to provide a custom renderer that allows you to display different coloured rows depending on your condition or requirements.
    Read a little more on the TreeCellRenderer here: http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html
    ICE

  • Saving NSDatePicker to a string and saving that to NSUserDefaults...

    Saving NSDatePicker to a string and saving that to NSUserDefaults I have it saved to a string then I have code that should save it to NSUSerDefaults so that when the program starts it is saved as the string not null. Here is the code [CODE]#import "MainView.h"
    #import "DateView.h"
    @implementation MainView
    -(void)awakeFromNib
    [self removeFromSuperview];
    [self addSubview:dateView];
    [dateView setdateandtime];
    [dateView permsavedattime];
    @end [/CODE] [CODE]#import "DateView.h"
    #include "MainView.h"//Use #import this is to see if #include Works
    @implementation DateView
    -(IBAction)showuserdefaultdate
    [self userdefaultdate];
    //dateoutput.text =tddate;
    -(void)permsavedattime
    tddate=[prefs stringForKey:@"testing"];
    tdtime=[prefs stringForKey:@"timetesting"];
    dateoutput.text =[[NSString alloc] initWithFormat:@"%@",tddate];
    -(void)userdefaultdate
    prefs =[NSUserDefaults standardUserDefaults];
    [prefs setInteger:tddate forKey:@"testing"];
    [prefs setObject:tdtime forKey:@"timetesting"];
    -(void)setdateandtime
    [Today setDate:[NSDate date] animated:YES];
    //formatting date style
    dateformatter = [ [ NSDateFormatter alloc ] init ];
    [ dateformatter setDateStyle:NSDateFormatterLongStyle];
    [ dateformatter setTimeStyle:NSDateFormatterNoStyle ];//makes it so the time is not included
    //[ formatter setTimeStyle:NSDateFormatterLongStyle ];//set to anystyle besides
    //NoStyle if you dont want time included.
    [Time setDate:[NSDate date] animated:YES];
    //formatting date style
    timeformatter = [ [ NSDateFormatter alloc ] init ];
    [ timeformatter setDateStyle:NSDateFormatterNoStyle];//makes it so it doesn't get the date
    [ timeformatter setTimeStyle:NSDateFormatterShortStyle];//makes it so the time is just hour and minute and A.M. or P.M.
    //[ formatter setTimeStyle:NSDateFormatterLongStyle ];//set to anystyle besides
    //NoStyle if you dont want time included.
    -(IBAction)recieveDate
    tddate= [dateformatter stringFromDate:Today.date];//Asigning the date to the string
    dateoutput.text =tddate;
    -(IBAction)recievetime
    tdtime= [timeformatter stringFromDate:Time.date];//Asigning the date to the string
    timeoutput.text =tdtime;
    -(IBAction)canceltime
    [Time setDate:[NSDate date] animated:YES];
    tdtime= [timeformatter stringFromDate:Time.date];//Asigning the date to the string
    timeoutput.text =tdtime;
    -(IBAction)canceldate
    [Today setDate:[NSDate date] animated:YES];
    tddate= [dateformatter stringFromDate:Today.date];//Asigning the date to the string
    dateoutput.text =tddate;
    @end[/CODE] What am I missing? It keeps coming up Null I need it saved right so I can send it through email

    softwarespecial wrote:
    why can't I have the prefs saved in the .h
    You can save that address in an ivar if you want to, but there's no purpose to that. The standardUserDefaults object is a +shared class object+. It's like a dictionary object that's maintained for your program by the NSUserPreferences class. You can read from or write to it at any time for the duration of your program. So whenever you get the shared object's address [NSUserDefaults standardUserDefaults], you're just getting the address of that same object each time.
    In case the above doesn't make sense, I ran across a good explanation by Danneman in the last message on this page: [http://www.iphonedevsdk.com/forum/iphone-sdk-development/18716-set-settings-va riable-code.html].
    When I did that as you so wisely pointed out it didn't work but when I saved it at each point I needed it it works.
    When you change two things at once it's easy to forget the first and assume the second change solved the problem. Actually, I don't think saving prefs in your ivar had anything to do with your bug. What fixed it was getting a pointer to the shared std defaults object in this method:
    -(void)permsavedattime
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; <-- get the shared object
    tddate=[prefs stringForKey:@"testing"];
    tdtime=[prefs stringForKey:@"timetesting"];
    dateoutput.text =[[NSString alloc] initWithFormat:@"%@",tddate];
    Without the first line of the above, I'm fairly sure that your prefs ivar was nil. I didn't see any code that initialized that ivar prior to the first time userdefaultdate ran. It looked to me like permsavedattime ran at start up, well before prefs was set in userdefaultdate. If you're interested in backtracking, restore the file to the way it was when you posted, then add a NSLog() like this:
    -(void)permsavedattime
    // NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; <-- get the shared object
    NSLog(@"prefs=%@", prefs);
    tddate=[prefs stringForKey:@"testing"];
    tdtime=[prefs stringForKey:@"timetesting"];
    dateoutput.text =[[NSString alloc] initWithFormat:@"%@",tddate];
    I wish to save lets say five different things to NSUSerDefaults would I be able to do it all with my NSUserDefaults prefs or would I have to create a another one for some of them?
    You know the answer to your second question now, right? The important point is that you're never creating the shared object, you're just asking for its address whenever you need it.
    Btw, there's another user defaults method you should know about: The synchronize method writes the data to disk. You might want to do that when your app is ready to exit. E.g., in the app delegate:
    - (void)applicationWillTerminate:(UIApplication *)application {
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    [prefs synchronize];
    Although the docs suggest synchronize when the app is about to exit, I'm not sure it's necessary. I think the system might write the defaults out to disk anyway when the app terminates, but not sure about this. +User Defaults Programming Topics for Cocoa+ says:
    On Mac OS X v10.5 and later, in applications in which a run-loop is present, synchronize is automatically invoked at periodic intervals. Consequently, you might synchronize before exiting a process, but otherwise you shouldn’t need to.
    The above is in the iPhone edition, so I think it applies.
    It might also be a good idea to update the data and call resetStandardUserDefaults in didReceiveMemoryWarning. I'm not clear about the need for reset either though, since the system may do that for you as well. But on a memory warning, you would definitely want to update the user default data if some of it is stored in an object to be released. You can find out how your app behaves on a memory warning by selecting Hardware->Simulate Memory Warning from the iPhone Simulator menu.
    - Ray

  • Thoughts on Stream-to-Disk Application and Memory Fragmentation

    I've been working on a LabVIEW 8.2 app on Windows NT that performs high-speed streaming to disk of data acquired by PXI modules.  I'm running with the PXI-8186 controller with 1GB of RAM, and a Seagate 5400.2 120GB HD.  My current implementation creates a separate DAQmx task for each DAQ module in the 8-slot chassis.  I was initially trying to provide semaphore-protected Write to Binary File access to a single log file to record the data from each module, but I had problems with this once I reached the upper sampling rates of my 6120's, which is 1MS/sec, 16-bit, 4-channels per board.  With the higher sampling rates, I was not able to 'start off' the file streaming without causing the DaqMX input buffers to reach their limit.  I think this might have to do with the larger initial memory allocations that are required.  I have the distinct impression that making an initial request for a bunch of large memory blocks causes a large initial delay, which doesn't work well with a real-time streaming app.
    In an effort to see if I could improve performance, I tried replacing my reentrant file writing VI with a reentrant VI that flattened each module's data record to string and added it to a named queue.  In a parallel loop on the main VI, I am extracting the elements from that queue and writing the flattened strings to the binary file.  This approach seems to give me better throughput than doing the semaphore-controlled write from each module's data acq task, which makes sense, because each task is able to get back to acquiring the data more quickly.
    I am able to achieve a streaming rate of about 25MB/sec, running 3 6120s at 1MS/sec and two 4472s at 1KS/sec.  I have the program set up where I can run multiple data collections in sequence, i.e. acquire for 5 minutes, stop, restart, acquire for 5 minutes, etc.  This keeps the file sizes to a reasonable limit.  When I run in this mode, I can perform a couple of runs, but at some point the memory in Task Manager starts running away.  I have monitored the memory use of the VIs in the profiler, and do not see any of my VIs increasing their memory requirements.  What I am seeing is that the number of elements in the queue starts creeping up, which is probably what eventually causes failure.
    Because this works for multiple iterations before the memory starts to increase, I am left with only theories as to why it happens, and am looking for suggestions for improvement.
    Here are my theories:
    1) As the streaming process continues, the disk writes are occurring on the inner portion of the disk, resulting in less throughput. If this is what is happening, there is no solution other than a HW upgrade.  But how to tell if this is the reason?
    2) As the program continues to run, lots of memory is being allocated/reallocated/deallocated.  The streaming queue, for instance, is shrinking and growing.  Perhaps memory is being fragmented too much, and it's taking longer to handle the large block sizes.  My block size is 1 second of data, which can be up to a 1Mx4x16-bit array from each 6120's DAQmx task.  I tried added a Request Deallocation VI when each DAQmx VI finishes, and this seemed to help between successive collections.  Before I added the VI, task manager would show about 7MB more memory usage than after the previous data collection.  Now it is running about the same each time (until it starts blowing up).  To complicate matters, each flattened string can be a different size, because I am able to acquire data from each DAQ board at a different rate, so I'm not sure preallocating the queue would even matter.
    3) There is a memory leak in part of the system that I cannot monitor (such as DAQmx).  I would think this would manifest itself from the very first collection, though.
    4) There is some threading/threadlocking relationship that changes over time.
    Does anyone have any other theories, or comments about one of the above theories?  If memory fragmentation appears to be the culprit, how can I collect the garbage in a predictable way?

    It sounds like the write is not keeping up with the read, as you suspect.  Your queues can grow in an unbounded fashion, which will eventually fail.  The root cause is that your disk is not keeping up.  At 24MBytes/sec, you may be pushing the hardware performance line.  However, you are not far off, so there are some things you can do to help.
    Fastest disk performance is achieved if the size of the chunks you write to disk is 65,000 bytes.  This may require you to add some double buffering code.  Note that fastest performance may also mean a 300kbyte chunk size from your data acquisition devices.  You will need to optimize and double buffer as necessary.
    Defragment your disk free space before running.  Unfortunately, the native Windows disk defragmentor only defragments the files, leaving them scattered all over the disk.  Norton's disk utilities do a good job of defragmenting the free space, as well.  There are probably other utilities which also do a good job for this.
    Put a monitor on your queues to check the size and alarm if they get too big.  Use the queue status primitive to get this information.  This can tell you how the queues are growing with time.
    Do you really need to flatten to string?  Unless your data acquisition types are different, use the native data array as the queue element.  You can also use multiple queues for multiple data types.  A flatten to string causes an extra memory copy and costs processing time.
    You can use a single-element queue as a semaphore.  The semaphore VIs are implemented with an old technology which causes a switch to the UI thread every time they are invoked.  This makes them somewhat slow.  A single-element queue does not have this problem.  Only use this if you need to go back to a semaphore model.
    Good luck.  Let us know if we can help more.
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • Loading a large number of strings into memory quickly

    Hello,
    I'm working on an iPhone application where I need to load a large number of strings into memory. Currently I'm simply reading from a file where each string is stored in plain text on a single line. I read the file contents into a string using stringWithContentsOfFile and then I create an NSSet object using NSSet setWithArray:[string componentsSeparatedByString:@"\n"]];
    This works like a charm but takes around 8 seconds to load on the iPhone. I'm looking for ways to speed this up. I've already tried a few things which weren't any faster:
    1) I used [NSKeyedArchiver archiveRootObject:myList toFile:appFile]; to store the NSSet data structure. Then instead of reading the text file storage. I read this file using [NSKeyedUnarchiver unarchiveObjectWithFile:appFile]; This was actually very slow and created a strings file that was about 2x the size of the original plain text.
    2) Instead of using an NSSet, I used and NSDictionary and used writeToFile and dictionaryWithContentsOfFile. This was also no faster.
    3) Finally I tried using the NSDictionary to write to a binary file format using NSPropertyListSerialization. This was also not any faster.
    I've been thinking about using SQLite instead of the flat file read, but I haven't had a chance to prototype that out to see if it would be faster. It's important that I can do fast searches for specific strings, which is why I originally used a set.
    Does any one else have any ideas how to load this into memory faster? If all else fails, I'm simply going to load the strings into memory using a separate thread on application launch so I don't prevent the user from getting to the main menu for 8 seconds.
    Thanks,
    -Keith

    I'd need to know more about what you're doing, but from what you're describing I think you should try to change your algorithm.
    For example: Instead of distributing one flat file, split your list of strings into 256 files, based on the first two hex digits of their MD5 hashes*. (Two digits might not be enough--you might need three or four. You may also want to use folders, especially if you need more than two digits.) When testing if a string exists, first calculate its MD5 hash and extract the necessary number of digits, then load that file into memory and scan its list. (You can cache these lists in memory so that you only have to load each file once--just make sure that a didReceiveMemoryWarning message will empty those caches.)
    Properly configured, SQLite may be faster than the eight second load time you talk about, especially if you ensure it indexes the column you store the strings in. But it's probably overkill for this application.
    \* A hash is a numeric code calculated from a string; on average, changing a single bit anywhere in the string should change half the bits in the hash, so even very similar strings should generate very different hashes. I suggest using MD5 instead of -\[NSString hash\] because the hash method is not guaranteed to return the same results on Mac OS and iPhone OS, or on different releases of either OS. You could also use a different algorithm, like a CRC; these are faster but I'm not as familiar with them. This thread discusses calculating MD5 hashes on iPhone OS: http://discussions.apple.com/thread.jspa?messageID=7362074
    Message was edited by: Brent Royal-Gordon

  • What Are the Differences Between String and StringBuffer?

    Both String and StringBuffer are final classes. StringBuffer grows in size dynamically. Could people help to detail other differences between String and StringBuffer?

    String is immutable. In other words, once it is made, the contents of that instance of String cannot be changed (easily). The size and characters cannot be changed, and code can take advantage of this fact to optimize space. Also, once you have a reference to a string, you do not need to worry about it changing at all, so you can eliminate constant tests to verify things such as size in another class that may want to hold onto the string.
    StringBuffer, as you noticed, can change dynamically. While this provides flexibility, it cannot be optimized and assumptions cannot be made as with strings. If a class holds a reference to a StringBuffer that it does not own, there is a possibility that it may change things such as size when the class tries to use it later. StringBuffer is also less efficient in handling space then an equivalent String. The character array to hold a String is exactly the length to hold all the characters. StringBuffer, on the other hand, adds a 16 character buffer of array space for possible expansions. Also, the size of the internal array doubles when its internal capacity is exceeded. So, unless you explicitly maintain the size, a StringBuffer will take up more memory then an equivalent String, and if your program needs thousands of instances of Strings (which is not uncommon), that space can add up.
    I hope this helps clarify some things for you.
    -JBoeing

  • What is difference between Null String and Empty String ?

    Hi
    Just i have little confusion that the difference bet'n NULL String and Empty String ..
    Please clear my doubte.
    Thankx

    For the same reason I think it's okay to say "null
    String" and "empty String "as long as you know they
    really mean "null String reference" and "empty String
    object" respectively. Crap. It's only okay to say that as long as *the one you're talking to" knows what it really means. Whether you know it or not is absolutely irrelevant. And there is hardly any ambiguity about the effects that a statement like "assign an object to a reference" brings. "Null String" differs in that way.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • HDD and memory upgrade on Satellite A350

    Hi All
    I have a satellite a350 laptop can anyone tell me whats the biggest harddrive I can have and memory please
    Thanks

    Hi
    The RAM upgrade depends on the available chipset.
    Not quite sure about your A350-xxx model but many of the Sat A350 notebooks were quipped with an Intel GM45 Express chipset and in such case you could upgrade the memory max up to 8GB RAM
    Regarding the HDD: This notebook supports SATA HDD. This mean that you are not limited to an special size.
    Theoretically it could be possible to use 500GB, 750GB 2.5 SATA HDDs

  • ITunes 10.7.0.21 crashing and memory usage

    Running on Windows 7 64 bit.  This is the first version I have had this issue with.  After running for several minutes, iTunes will do one of three things:
    Crash
    Freeze, and require me to force it closed in the task manager
    Display a recurring message about not enough memory
    Watching it more closely, iTunes seems to continue to take up more and more memory the longer it is running, which I suspect is the cause of all three symptoms.
    Anyone else experiencing this memory leak problem?
    Is this just a problem with this version that I'll have to wait until the next one, or is there a fix?

    I am having the very same issues, admittedly with and older (5 yrs) Windows Vista 32-bit Dell laptop. I had been holding out for a little while on allowing iTunes to upgrade on my computer, and had no issues or complaints with iTunes 7, 8, or 9. But after I allowed it to upgrade today, 10.7 is worthless.
    After a few minutes, iTunes pops up with a message regarding insufficient memory, freezes, then crashes. Not even using video, just putting together a playlist of regular file size songs.
    I know after reading a bit on the boards that trying to re-install version 9 may cause some things to be lost in translation from 10 to 9, apparently because of some changes in the way the software is set up. Please correct me if that is not the case.
    However, I would rather risk it (I have all of my music files on an external hard drive) than to keep having iTunes behave as it is- making the software that I've been using for years worthless to me since it cannot work correctly.
    By the by, I know my laptop is ancient by technology standards, but won't be upgrading quite yet.
    If you know a reliable source to download the previous versions of iTunes for Windows, I'd be grateful if you could point me in the right direction. I'm fairly computer savvy, and know that I'll need to un-install the most recent iTunes version prior to installing an older version.

  • A few questions about MacBooks and Parallels Desktop.

    I have a few questions about MacBooks and Parallels Desktop.
    1) I understand I need at least 1GB of RAM to run Parallels Desktop but what about the hard drive, is the stock 60GB drive big enough?
    2) Related to question 1, even if it was big enough to allow me to install and run Windows would the 60GB drive be enough if I wanted to install a Linux distribution as well?
    3) This has nothing to do with Parallels Desktop but thought I'd ask it here anyway, do Apple Stores carry just the stock MacBooks, or do they carry other configurations?
    Thanks
    Keith

    1. Depend on how intensive you use that HD for saving data on both Mac OS and XP. For standard installation on both OS X and XP, the space of 60 Gb is enough.
    2. Same answer as no 1. You can install all three on that HD space, but the extra spacce available will be less and less for your data. You can save your data on external or back up on cd/dvd and erase it from the HD to keep the free space.
    Remember to leave at least 2 or 3 Gb for virtual memory usage.
    3. Just call them, maybe they don't have it in store stock, but by appointment they might configure one for you before your pick-up date.
    Good Luck

  • Nio ByteBuffer and memory-mapped file size limitation

    I have a question/issue regarding ByteBuffer and memory-mapped file size limitations. I recently started using NIO FileChannels and ByteBuffers to store and process buffers of binary data. Until now, the maximum individual ByteBuffer/memory-mapped file size I have needed to process was around 80MB.
    However, I need to now begin processing larger buffers of binary data from a new source. Initial testing with buffer sizes above 100MB result in IOExceptions (java.lang.OutOfMemoryError: Map failed).
    I am using 32bit Windows XP; 2GB of memory (typically 1.3 to 1.5GB free); Java version 1.6.0_03; with -Xmx set to 1280m. Decreasing the Java heap max size down 768m does result in the ability to memory map larger buffers to files, but never bigger than roughly 500MB. However, the application that uses this code contains other components that require the -xMx option to be set to 1280.
    The following simple code segment executed by itself will produce the IOException for me when executed using -Xmx1280m. If I use -Xmx768m, I can increase the buffer size up to around 300MB, but never to a size that I would think I could map.
    try
    String mapFile = "C:/temp/" + UUID.randomUUID().toString() + ".tmp";
    FileChannel rwChan = new RandomAccessFile( mapFile, "rw").getChannel();
    ByteBuffer byteBuffer = rwChan.map( FileChannel.MapMode.READ_WRITE,
    0, 100000000 );
    rwChan.close();
    catch( Exception e )
    e.printStackTrace();
    I am hoping that someone can shed some light on the factors that affect the amount of data that may be memory mapped to/in a file at one time. I have investigated this for some time now and based on my understanding of how memory mapped files are supposed to work, I would think that I could map ByteBuffers to files larger than 500MB. I believe that address space plays a role, but I admittedly am no OS address space expert.
    Thanks in advance for any input.
    Regards- KJ

    See the workaround in http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4724038

  • How to get information about limitation Internal Memory on device

    hallo ..
    have some question here, so please some person able to answer my questions 
    1. How to get Information about limitation internal memory on device 
    2. is possible to improve internal memory on Blackberry ( move apps on external memory )
    3. any tools to get internal memory activity ?
    thanks for this people who joins here, hope we can share more information about blackberry .. 

    In addition...
    There are three types of potential memory on a BB: 1) Application Memory, 2) Device Memory, and 3) Media/SD Card Memory.
    Application Memory -- This is the most crucial; it is the protected (not user accessible), dedicated, and fixed (in size) space that is available as the destination for the installation of applications (plus some application storage, overhead and such). You cannot touch AppMemory. You cannot improve the maximum AppMemory that your BB has. It is what it is. Applications can only install here...there is no option.
    Device Memory -- This is space on your BB that you can touch to store files, pictures, media, etc. Typically, it is not terribly large, but it is available to you.
    SD/Media Card Memory-- This is what it says...your SD card, for you to store files, media, pictures, etc. It can be as large as your BB OS can support...see this KB:
    KB05461MicroSD card sizes supported by the BlackBerry device software
    On some devices/OS levels, you can only see "File Free" (Options > Status), which I think is equivalent to AppMemory. On other devices, you can see all three memory usage levels (Options > Memory). Here are some guidelines to use:
    KB02843What is the Low Memory Manager feature on the BlackBerry smartphone
    KB14320How to maximize free space and battery power on the BlackBerry smartphone
    KB14213Call logs, SMS text messages, and email messages are deleted from the BlackBerry smartphone
    Lastly, it is always important to properly close applications when you are done with them. Using the Back or the Red key will not do this -- those leave it to the app to decide what to do...and some will leave themselves resident in memory, consuming resources on your BB, slowing the overall performance. Rather, to close an app, press and select "Close" or "Exit"...that will force the application to be closed, freeing up for your new use the resources it was consuming. Some apps will always remain running (typically -- BBMessenger, Browser, Homescreen, Phone, and Messages)...but, you should still close them properly - especially the Browser...if it is left on an active web page, it will not only consume extra resources but battery power as well.
    Further, anytime random strange behavior or sluggishness creeps in, the first thing to do is a battery pop reboot. With power ON, remove the back cover and pull out the battery. Wait about a minute then replace the battery and cover. Power up and wait patiently through the long reboot -- ~5 minutes. See if things have returned to good operation. Like all computing devices, BB's suffer from memory leaks and such...with a hard reboot being the best cure. Some have taken to doing this on a regular basis as a preventive measure...some as frequently as once per day. Others have obtained the QuickPull app to automate a simulated Batt-Pull.
    Good luck!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Jdev11g CPU profile and Memory Profile doesn't work for Mac

    I'm running Jdev11g on Mac OSX 10.5.5,
    CPU Profile and Memory Profile doesn't work. I got following message:
    Error occurred during initialization of VM
    Could not find agent library in absolute path: /Shared/jdevjavabase11110/jdeveloper/jdev/lib/profiler16.so
    The file actually is there. I don't understand why they looking for .so file, it supposed to be mapped as .jnilib on Mac.
    This is broken on TP4 as well.

    I'm still seeing this issue. Here is what I get:
    /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/java -client "-agentpath:/Users/kamleshnanda/Downloads/jdeveloper/jdev/lib/profiler16.so=port=60950,jarpath=/Users/kamleshnanda/Downloads/jdeveloper/jdev/lib/profiler-agent.jar,enable=t,depth=1000,startup=connect,time" -classpath /Users/kamleshnanda/jdeveloper/mywork/MyJavaApplication/Project1/classes project1.Class1 Hello
    Error occurred during initialization of VM
    Could not find agent library in absolute path: /Users/kamleshnanda/Downloads/jdeveloper/jdev/lib/profiler16.so
    Process exited with exit code 1.
    I'm using the following build:
    About
    Oracle JDeveloper 11g Release 1 11.1.1.2.0
    Java Edition Version 11.1.1.2.0
    Build JDEVADF_11.1.1.2.0_GENERIC_091029.2229.5536
    Copyright © 1997, 2009 Oracle and/or its affiliates. All rights reserved.
    IDE Version: 11.1.1.2.36.55.36
    Product ID: oracle.jdeveloper
    Product Version: 11.1.1.2.36.55.36
    Version
    Component     Version
    =========     =======
    CVS Version (External)     (CVS) 1.12.13 (client/server)
    Java(TM) Platform     1.6.0_17
    Oracle IDE     11.1.1.2.36.55.36
    PMD     JDeveloper Extension 4.2.5.3.0
    Team Productivity Center     11.1.1.2.36.55.36
    Versioning Support     11.1.1.2.36.55.36
    Here are the JVM properties:
    java.runtime.name     Java(TM) SE Runtime Environment
    java.runtime.version     1.6.0_17-b04-248-10M3025
    java.specification.name     Java Platform API Specification
    java.specification.vendor     Sun Microsystems Inc.
    java.specification.version     1.6
    java.vendor     Apple Inc.
    java.vendor.url     http://www.apple.com/
    java.vendor.url.bug     http://bugreport.apple.com/
    java.version     1.6.0_17
    java.vm.info     mixed mode
    java.vm.name     Java HotSpot(TM) 64-Bit Server VM
    java.vm.specification.name     Java Virtual Machine Specification
    java.vm.specification.vendor     Sun Microsystems Inc.
    java.vm.specification.version     1.0
    java.vm.vendor     Apple Inc.
    java.vm.version     14.3-b01-101
    Here is the OS information:
    os.arch     x86_64
    os.name     Mac OS X
    os.version     10.6.2

Maybe you are looking for

  • Adding attachments to Reader enabled forms in Adobe reader

    I am creating a form for a user where they need to add an attachment to the form from Adobe Reader. They also need to save the form locally, as this is a low volume usage, approx. 100 uses in total the rights are being enabled in Acrobat Professional

  • Accessing ai0 to ai16 on DAQ and performing operations on them

    Hi all, I have a problem, I am using an NI-Daq interface board, I am able to get the waveforms ( plot of the 16 channels collectively) and work the interface correctly, but the problem is  I have to perform different operations on each of the 16 chan

  • Modify  webservice URL

    Hello, I am in need to modifying the a webservice URL at runtime. I used the improt wizard to import my webservice. I see its defined in the .settings/webservices.xml file but i dont know how to access that via code? Can this be done ? Drew

  • HT3204 how do i get a song as a ring tone

    I want to use a song i have downloaded as my ring tone how do i get it to my default ringtone

  • Snow White and the apple

    I have been an apple lover and user since 1990 and dreamed of owning my own. I always loved the quality of the hardware and the software and the development method by listening to what their customers wanted. I eventually made my dreams come true in