问题标签 [sbrk]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
6 回答
45948 浏览

c - 对 _sbrk 的未定义引用

我遇到了问题_sbrk。在编译的链接阶段,我使用下面的命令来链接我的对象,我得到未定义的引用_sbrk

我正在为arm926ej-s和 ARM 模式编译,所以我认为我选择了正确的 multilib ( libc.aand libgcc.a),它位于文件夹中home/ziga/projects/cs_lite/arm-none-eabi/lib/

我一直在互联网上搜索_sbrk功能,它是某种内存管理调用,它不包含在标准 C 库中,因为它依赖于微处理器。那么我必须自己编写_sbrk函数吗?我该怎么做?你有arm926ej-s 的例子吗?编写此函数后,我打算将其编译为目标文件并将其与其他对象、库链接在一起。

0 投票
2 回答
4899 浏览

c - brk 和 sbrk 代表什么?

虽然我知道 Unix 系统调用brk和函数的作用sbrk,但我不知道它们代表什么。任何人都可以启发我吗?

0 投票
2 回答
1388 浏览

c - 如何设置 void 的值 **

所以我尝试使用以下代码在不使用 malloc 的情况下向堆中添加一些内存(size 是函数中的无符号 int 参数,而不是设定的数字)

现在我想将 temp 中的 void * 的值设置为 NULL,但是当我尝试这样做时

我的编译器告诉我不能取消引用 void *. 我该如何解决这个错误?

0 投票
2 回答
480 浏览

c - 分配适当的内存大小

我在我的程序中分配正确大小的内存时遇到问题。我执行以下操作:

当我这样做时,我认为它向堆中添加了太多内存,因为它以 void* 而不是字节为单位分配它。我如何告诉它我希望 sizeof( whatever ) 表示任何字节而不是任何其他单位?

编辑:

我见过其他人将事物转换为字符,以便编译器以字节为单位获取大小。如果 sizeof(unsigned int) 是 4 字节,但我使用的类型是 void *,编译器会破坏 void * 大小的 4 倍而不是 4 字节吗?

0 投票
2 回答
3792 浏览

linux - Linux sbrk() 作为汇编中的系统调用

因此,作为一项挑战和性能,我正在编写一个简单的汇编服务器。我知道的唯一方法是通过系统调用。(通过int 0x80)显然,我需要比在组装或加载时分配的更多内存,所以我阅读并决定我想使用sbrk(),主要是因为我不理解mmap():p

无论如何,Linux 没有为 sbrk() 提供中断,只有 brk()。

那么...如何找到当前程序中断以使用 brk()?我考虑过使用 getrlimit(),但我不知道如何获取资源(我猜是进程 ID)传递给 getrlimit()。或者我应该找到其他方法来实现 sbrk()?

0 投票
1 回答
1257 浏览

c - sbrk(size_t) 中的分段错误

我的程序很简单,

当我调试它时,它显示:

Program received signal SIGSEGV, Segmentation fault.TO_INT((pool_tail - 3)) = BUF_LENGTH * -1;

pool_tail & pool_head 的值:

pool_tail = 0x805a000

pool_head = 0x804a000

如何解决?谢谢!

0 投票
0 回答
679 浏览

arm - 手臂霓虹灯代码上的链接器错误

我正在使用 c 内在函数处理 ARM neon 代码。当我编译文件时,我不断收到以下错误:

c:/program files (x86)/codesourcery/sourcery g++ lite/bin/../lib/gcc/arm-none-ea bi/4.3.3/../../../../arm-none -eabi/bin/ld.exe:警告:找不到入口符号_start;默认为 00008020

c:/program files (x86)/codesourcery/sourcery g++ lite/bin/../lib/gcc/arm-none-ea bi/4.3.3/../../../../arm-none -eabi/lib\libc.a(lib_a-exit.o):在函数“exit”中:exit.c:(.text+0x28):未定义对“_exit”的引用

c:/program files (x86)/codesourcery/sourcery g++ lite/bin/../lib/gcc/arm-none-ea bi/4.3.3/../../../../arm-none -eabi/lib\libc.a(lib_a-fstatr.o):在函数“_fst at_r”中:fstatr.c:(.text+0x1c):未定义对“_fstat”的引用

c:/program files (x86)/codesourcery/sourcery g++ lite/bin/../lib/gcc/arm-none-ea bi/4.3.3/../../../../arm-none -eabi/lib\libc.a(lib_a-openr.o):在函数“_open _r”中:openr.c:(.text+0x20):未定义对“_open”的引用

c:/program files (x86)/codesourcery/sourcery g++ lite/bin/../lib/gcc/arm-none-ea bi/4.3.3/../../../../arm-none -eabi/lib\libc.a(lib_a-sbrkr.o):在函数'_sbrk _r'中:sbrkr.c:(.text+0x18):未定义引用'_sbrk'

c:/program files (x86)/codesourcery/sourcery g++ lite/bin/../lib/gcc/arm-none-ea bi/4.3.3/../../../../arm-none -eabi/lib\libc.a(lib_a-writer.o): 在函数'_write_r':writer.c:(.text+0x20): 未定义引用'_write'

c:/program files (x86)/codesourcery/sourcery g++ lite/bin/../lib/gcc/arm-none-ea bi/4.3.3/../../../../arm-none -eabi/lib\libc.a(lib_a-closer.o):在函数“_close_r”中:closer.c:(.text+0x18):未定义对“_close”的引用

c:/program files (x86)/codesourcery/sourcery g++ lite/bin/../lib/gcc/arm-none-ea bi/4.3.3/../../../../arm-none -eabi/lib\libc.a(lib_a-isattyr.o): 在函数'_is atty_r':isattyr.c:(.text+0x18): 未定义引用'_isatty'

c:/program files (x86)/codesourcery/sourcery g++ lite/bin/../lib/gcc/arm-none-ea bi/4.3.3/../../../../arm-none -eabi/lib\libc.a(lib_a-lseekr.o): 在函数 '_lse ek_r':lseekr.c:(.text+0x20): 未定义引用'_lseek'

c:/program files (x86)/codesourcery/sourcery g++ lite/bin/../lib/gcc/arm-none-ea bi/4.3.3/../../../../arm-none -eabi/lib\libc.a(lib_a-readr.o): 在函数 '_read _r':readr.c:(.text+0x20): 未定义引用 '_read'

collect2: ld 返回 1 个退出状态

谁能告诉我如何纠正这些错误?我所知道的是我必须明确定义函数isatty()fstat。但我不知道在哪里定义它们

0 投票
1 回答
596 浏览

c - 关于我首先拟合 malloc 函数的方法的意见和建议

我正在为大学作业编写 malloc 函数。这是我的想法的基本布局:

1)定义一个节点结构,其中包含指向前一个节点、下一个节点的指针,以及一个用于大小和空缺的字符。堆中的每个区域都将包含一个带有此信息的隐藏节点。

2)malloc函数。从第一个节点循环开始,通过每个节点检查空缺。如果一个节点是空的并且足够大,则将一个 ptr 返回到不包括该节点的区域的开头。如果没有可用空间,请使用 sbrk 为节点分配请求的空间 PLUS 空间。

3)自由功能。转到作为参数sizeof(结构节点)传递的指针并将空缺设置为空缺。然后从列表的开头开始,遍历列表合并相邻的空闲空间。

这种方法听起来如何?我主要关心的是实际启动链表。例如,在开始进行任何分配并将 ptr 作为全局变量存储到它之前,是否应该使用 sbrk 创建一个节点?如果是这样,在允许驱动程序调用 malloc 函数之前如何初始化第一个节点?

提前致谢。我不是要求有人编写我的代码,只是为了提供一些关于我的想法的见解和建议。

0 投票
5 回答
8539 浏览

linux - How to return memory from process to the OS

I have an issue with memory management in various operating systems.

My program is a server that does some processing that could take a few GB of memory. After that, it releases most of the memory while it waits for a few hours until another request arrives.

On AIX and Solaris, I observe the following behavior,

When I free memory, the memory is not returned back to the operating system. The amount of virtual memory used by a process always increases - never decreases. The same is true for the physical memory, up to its limit. Thus it appears that we use all this memory in sleep mode as well.

When this memory can be returned back to OS? How can I make it?

Linux is different: it appears that is does return memory sometimes, but I'm not able to understand when and how. I have for example a scenario in which the process before a request was 100MB, then 700MB at the peak, and after releasing all that it was down to 600MB. I don't understand it - if Linux gives back memory to the OS, why not all of it?

0 投票
1 回答
255 浏览

gcc - 似乎 malloc 要求的内存太多

我有一个使用 yagarto GCC 编译器的 STM32F0 应用程序。我已经实现了_sbrk newlib_stubs.c。我遇到的问题是我在调用 _sbrk 并要求 4K 内存时调用 malloc(256) 依次调用 malloc。我的系统总共只有 8K,所以显然这是个问题。我已经监视了对 _sbrk 的调用,它似乎在分配较少的内存之前进行了一些调用。

现在我正在通过捂住鼻子避免恶臭并做类似的事情来解决这个问题:

在我重新定位堆之前在 _sbrk 中。

尽管该系统看起来坚如磐石,但我相当肯定它会在我最不期待的时候再次出现并困扰我。