e673. Getting Amount of Free Accelerated Image Memory

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

转载于:https://www.cnblogs.com/borter/p/9575538.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值