是否有任何其他半/便携的方式来动态分配内存? [英] Are there any other semi/portable ways to dynamically allocate memory?

查看:86
本文介绍了是否有任何其他半/便携的方式来动态分配内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这样的:

char *buf = NULL;
scanf("%ms", &buf);

会得到一个动态分配的字符缓冲区。我知道这是仅限于与海湾合作委员会(特别是glibc的2.7版本)。

will get a dynamically allocated char buffer. I know this is limited to code compiled with Gcc (and specifically version 2.7 of glibc).

我也知道,正确和简单的方法是只使用的malloc()(朋友)来获得内存。

I am also aware that the "correct" and portable way is to just use malloc() (and friends) to get the memory.

我很好奇,但是,还有没有其他的便携式或半便携式 * 实现了那里获得动态分配的内存?我觉得技巧和内存分配的提示,在C硬话题谷歌。

I'm curious however, are there any other portable or semi-portable* implementations out there for getting dynamically allocated memory? I find tricks and tips of memory allocation in C a hard topic to "Google".

注意:这不是什么必需的,所以有对答案没有限制。

Note: This is not "required" for anything, so there are no limitations on answers.

<子> *半便携式意思是如果你编译以同样的方式我这样做,这将工作

推荐答案

POSIX有

ssize_t getline(char **lineptr, size_t *n, FILE *stream);

ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);

这应该有资格作为半便携。

which should qualify as semi-portable.

这篇关于是否有任何其他半/便携的方式来动态分配内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆