首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对加热设备的繁重CPU处理

对加热设备的繁重CPU处理
EN

Stack Overflow用户
提问于 2015-01-02 05:26:28
回答 1查看 331关注 0票数 3

我的公司已经创建了一个企业应用程序,用于现场使用。

我们发现我们的iPhone 5在0*C以下不能正常工作。

我们正在尝试的一个解决方案是运行高CPU密集型任务(相当于运行3D游戏),这会给设备增加热量(除了我们用来帮助他们的其他外部热量之外)。

我在室内使用激光测温仪作为基准,当iPhone 5在应用程序主屏幕上处于空闲状态时,我在屏幕上测量了24*C。当我启动一款密集的3D游戏时,手机会预热,屏幕在几分钟内就会显示35*C。

我们如何在不消耗资源和应用程序崩溃的情况下重新创建密集的后台线程CPU进程?我尝试过GitHub的各种开源iOS基准测试应用程序,但当我将它们放在后台线程的无限循环中时,几分钟后应用程序就会耗尽内存并崩溃。

这是我在无限循环中放到后台的一个基准的例子。(while 1=1)。无论我尝试哪种基准测试代码,"Total Bytes“都会一直增长,直到应用程序崩溃。Click to see Instruments Screenshot.

有没有人有CPU密集型代码的例子,我可以用来让设备变得漂亮和热,并防止应用程序无限期地消耗资源?

电池耗尽不是问题,因为我们将使用连接的外部电池组来抵消任何耗尽。

感谢大家的帮助!

亚当

代码语言:javascript
复制
    UIApplication * application = [UIApplication sharedApplication];

if([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)])
{
    NSLog(@"Multitasking Supported");

    __block UIBackgroundTaskIdentifier background_task;
    background_task = [application beginBackgroundTaskWithExpirationHandler:^ {

        //Clean up code. Tell the system that we are done.
        [application endBackgroundTask: background_task];
        background_task = UIBackgroundTaskInvalid;
    }];

    //To make the code block asynchronous
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{

        //### background task starts
        NSLog(@"Running in the background\n");
        static NSString *staticString = @"some const value string to referece";
        while (1 == 1)
        {
            NSDictionary *dictionary;
            NSString *string;
            NSDate *staticStart = [NSDate date];
            NSLog(@"start timing");
            int times = 10000000;
            while (times--) {
                static dispatch_once_t onceToken;
                static NSDictionary *dict;
                dispatch_once(&onceToken, ^{
                    dict = @{@"somekey":@"someotherlongvalue", @"someotherkey":@"someotherlongvalue", @"onelastkey":@"onelastvalue"};
                });
                dictionary = dict;
            }
            NSDate *staticEnd = [NSDate date];
            NSLog(@"finished static dict in %f sec", [staticEnd timeIntervalSinceDate:staticStart]);

            times = 10000000;
            while (times--) {
                dictionary = @{@"somekey":@"someotherlongvalue", @"someotherkey":@"someotherlongvalue", @"onelastkey":@"onelastvalue"};
            }

            NSDate *dictEnd = [NSDate date];
            NSLog(@"finished dict create in %f sec", [dictEnd timeIntervalSinceDate:staticEnd]);

            times = 10000000;
            while (times--) {
                static dispatch_once_t stringOnceToken;
                static NSString *dispatchString;
                dispatch_once(&stringOnceToken, ^{
                    dispatchString = @"someotherlongvalue";
                });
                string = dispatchString;
            }
            NSDate *staticStringEnd = [NSDate date];
            NSLog(@"finished static string in %f sec", [staticStringEnd timeIntervalSinceDate:dictEnd]);
            times = 10000000;
            while (times--) {
                string = @"someotherlongvalue";
            }
            NSDate *stringEnd = [NSDate date];
            NSLog(@"finished string create in %f sec", [stringEnd timeIntervalSinceDate:staticStringEnd]);
            times = 10000000;
            while (times--) {
                string = staticString;
            }
            NSDate *refEnd = [NSDate date];
            NSLog(@"finished string reference in %f sec", [refEnd timeIntervalSinceDate:stringEnd]);
        }
        //#### background task ends

        //Clean up code. Tell the system that we are done.
        [application endBackgroundTask: background_task];
        background_task = UIBackgroundTaskInvalid; 
    });
}
else
{
    NSLog(@"Multitasking Not Supported");
}
EN

回答 1

Stack Overflow用户

发布于 2015-01-02 06:15:52

你有很多自动释放的对象,它们从来没有机会被释放。将自动释放池添加到您的外部循环:

代码语言:javascript
复制
while (1 == 1) {
    @autoreleasepool {
        // original contents of your loop
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27734837

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档