Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Memory allocation time

Reply
Thread Tools

Memory allocation time

 
 
Arne Vajh°j
Guest
Posts: n/a
 
      10-26-2008
Chronic Philharmonic wrote:
> "Arne Vajh°j" <(E-Mail Removed)> wrote in message
> news:48fb9e98$0$90273$(E-Mail Removed)...
>> Chronic Philharmonic wrote:
>>> <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> I execute the following snippet of code:
>>>>
>>>> public static void main(String[] args)
>>>> {
>>>> while(true)
>>>> {
>>>> long startTime = System.currentTimeMillis();
>>>> byte[] bytes = new bytes[1024*1024];
>>>> System.out.println("Time taken : " + (System.currentTimeMillis()
>>>> - startTime));
>>>> }
>>>> }
>>>>
>>>> After every few iterations it takes 52 ms for the allocation. Why? How
>>>> can I reduce the time taken?
>>> Just guessing... After a while, the JVM does some garbage collection to
>>> reclaim the bytes you are no longer using. Each new assignment to bytes
>>> discards the reference to the previous one. So you're just churning
>>> through memory. Roughly speaking, the JVM lets the old references
>>> accumulate until there isn't enough memory to allocate another one. Then
>>> it has to stop and clean up memory.
>>>
>>> I am not aware of any way you can change this behavior.

>> There is a gazillion -X and -XX options to control GC behavior.

>
> Perhaps I should have said I am not aware of any particular way to change
> this behavior. I did mention -Xms and -Xmx as a possible starting place. But
> the basic problem won't necessarily change. The OP is just generating a lot
> of unreferenced memory. Unless there's a good reason for that (I assumed
> perhaps this was a simplified case that involved cycling through video
> buffers or something), the only way to change the fundamental problem would
> be to not do that.


Some of the GC options will have an effect on the "GC pausing".

Like:
-XX:MaxGCPauseMillis=10

Arne
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
An idea for heap allocation at near stack allocation speed Bjarke Hammersholt Roune C++ 14 03-06-2011 08:07 AM
static memory allocation versus dynamic memory allocation Ken C Programming 24 11-30-2006 12:37 AM
What is the difference between dynamic memory allocation,and stack allocation ? chris C++ 6 10-28-2005 05:27 AM
memory allocation and freeing memory Rodrigo Dominguez C Programming 11 06-14-2005 11:54 PM
Dynamic memory allocation and memory leak... s.subbarayan C Programming 10 03-22-2005 02:48 PM



Advertisments