码迷,mamicode.com
首页 > 其他好文 > 详细

e673. Getting Amount of Free Accelerated Image Memory

时间:2018-09-03 00:04:02      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:each   cal   for   body   ica   around   volatil   ems   The   

Images in accelerated memory are much faster to draw on the screen. However, accelerated memory is typically limited and it is usually necessary for an application to manage the images residing in this space. This example demonstrates how to determine the amount free accelerated available.

Note: There appears to be a problem with GraphicsDevice.getAvailableAcceleratedMemory() on some systems. The method returns 0 even if accelerated image memory is available. A workaround is to create a temporary volatile image on the graphics device before calling the method. Once the volatile image is created, the method appears to return the correct value on all subsequent calls.

See also e601 Enabling Full-Screen Mode and e674 创建并绘制加速图像.

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        GraphicsDevice[] gs = ge.getScreenDevices();
    
        // Get current amount of available memory in bytes for each screen
        for (int i=0; i<gs.length; i++) {
            // Workaround; see description
            VolatileImage im = gs[i].getDefaultConfiguration().createCompatibleVolatileImage(1, 1);
    
            // Retrieve available free accelerated image memory
            int bytes = gs[i].getAvailableAcceleratedMemory();
            if (bytes < 0) {
                // Amount of memory is unlimited
            }
    
            // Release the temporary volatile image
            im.flush();
        }
    } catch (HeadlessException e) {
        // Is thrown if there are no screen devices
    }

 

Related Examples

e673. Getting Amount of Free Accelerated Image Memory

标签:each   cal   for   body   ica   around   volatil   ems   The   

原文地址:https://www.cnblogs.com/borter/p/9575538.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!