gpt4 book ai didi

ios - 繁重的 CPU 处理以加热设备

转载 作者:搜寻专家 更新时间:2023-10-30 20:16:39 26 4
gpt4 key购买 nike

我的公司创建了一个在现场使用的企业应用程序。

我们发现我们的 iPhone 5 在低于 0*C 的温度下无法正常工作。

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

在室内使用激光温度计作为基准,当 iPhone 5 在应用程序主屏幕上闲置时,我在 iPhone 5 屏幕上测量了 24*C。当我启动密集型 3D 游戏时,手机变热并且屏幕在几分钟内达到 35*C。

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

这是我在无限循环中放入后台的基准测试之一的示例。 (而 1=1)。无论我尝试什么样的基准代码变体,“总字节数”都会不停地增长,直到应用程序崩溃。 Click to see Instruments Screenshot.

有没有人有我可以使用的 CPU 密集型代码的示例,这些代码可以使设备变热并防止应用无限期地占用资源?

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

感谢所有帮助!

亚当

    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");
}

最佳答案

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

while (1 == 1) {
@autoreleasepool {
// original contents of your loop
}
}

关于ios - 繁重的 CPU 处理以加热设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27734837/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com