完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
特别是XC32的实现,因为我知道它们都是不同的。我了解MalCube()做什么:你要求X字节,它返回一个指向那个内存段开始的指针。但是如果我使用了一个带有200K堆的部件,并且说我是MalCube()50K,然后是100K……那么,我将(50k)(和)重新分配到另一个90K?有东西告诉我,这将失败,因为我怀疑任何东西都在后台移动。我以前从未在嵌入式系统上使用过MalCube(),因为它不是100%的效率,而是我自己制作的非常粗糙的系统,在那里我必须以反顺序的顺序释放任何分配的块。阳离子。这是棘手的,因为它需要大量的调试。但是现在我在设计一个带有大量RAM的PIC32 MZ,我不关心一些浪费(这就是我们如何使用PC,我知道)。当使用MalCube()来分配稍后将被释放的大块RAM时,有哪些最佳实践?分配顺序需要考虑吗?
以上来自于百度翻译 以下为原文 ....especially the XC32 implementation since I understand they are all different? I understand what malloc() does: you ask for x bytes and it returns a pointer to the start of that memory section. But what happens if I am using a part with 200K heap and say I malloc() 50K, then 100K....then I free() the 50K and attempt to malloc() another 90K? Something tells me this will fail because I doubt anything is getting moved around in the background. I've never used malloc() on an embedded system before because it's not 100% efficient, but rather I made my own very crude system where I'd have to free any allocated chunks in reverse order of allocation. This was touchy though as it required a lot of debugging. But now I'm looking at designing with a PIC32MZ with so much RAM I don't care about some waste (and that's how we got to where we are with the PC, I know). What are some best practices when using malloc() to allocate large chunks of RAM that will be freed at a later time? Is order of allocation something to consider? |
|
相关推荐
3个回答
|
|
堆碎片是在小型嵌入式系统中通常避免MALLC的主要原因。严格地在反向分配顺序中释放通常避免碎片化,但这仍然是分配器的实现细节,通常不被记录。池分配器(固定大小块的数组)是一种非常常见的避免碎片化的方法,但它们当然不那么通用。
以上来自于百度翻译 以下为原文 Heap fragmentation is the big reason malloc is usually avoided in small embedded systems. Freeing strictly in reverse allocation order usually avoids fragmentation, but that is still an implementation detail of the allocator that is usually not documented. Pool allocators (arrays of fixed-sized blocks) are a pretty common method for avoiding fragmentation, but they're of course less general. |
|
|
|
你确实会有漏洞,只是像一个堆栈的反向顺序。当释放内存时,任何相邻的孔都应该包含在内存池中。1000 UFED50 FLU100使用20×FLU8080 UPDEF,释放100个内存区域,它应该与50和20连接,170个空闲。如果你想使用大量的SMAL。l分配,分配更大的尺寸并使用它。
以上来自于百度翻译 以下为原文 You do get holes, just free in the reverse order like a stack. When freeing memory, any adjacent holes should be included in the memory pool. 1000 Used 50 Free 100 Used * 20 Free 80 Used If you free the 100 memory region, it should join up with 50 and 20, giving 170 free. If you intend to use a lot of small allocations, alloc a larger size and use that. |
|
|
|
在更大的实时系统中也需要避免。RTOS通常会有自己的内存池支持。所有需要的内存在启动时静态分配,以避免MalCube(For)、For()等的不确定性行为,…
以上来自于百度翻译 以下为原文 It's also to be avoided in larger real time systems. RTOS will often have their own memory pool support. All required memory is statically allocated at startup to avoid non-deterministic behaviour of malloc(), free(), etc., ... |
|
|
|
只有小组成员才能发言,加入小组>>
5248 浏览 9 评论
2036 浏览 8 评论
1956 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3217 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2264 浏览 5 评论
786浏览 1评论
677浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
603浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
684浏览 0评论
581浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-27 03:44 , Processed in 1.144559 second(s), Total 51, Slave 45 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号