V2EX  ›  英汉词典

Malloc

释义 Definition

malloc 是 C 语言标准库函数,用于在堆(heap)动态分配指定字节数的内存,并返回指向该内存块起始地址的指针;若分配失败通常返回 NULL。(在 C++ 中更常用 new,但也能调用 malloc。)

发音 Pronunciation (IPA)

/ˈmæ.lɒk/ (英式常见)
/ˈmæ.lɑːk/ (美式常见)

例句 Examples

I used malloc to allocate 100 bytes.
我用 malloc 分配了 100 个字节的内存。

The program calls malloc to create an array at runtime, checks for NULL, and then frees the memory to avoid leaks.
程序在运行时调用 malloc 创建数组,检查是否为 NULL,并在最后释放内存以避免内存泄漏。

词源 Etymology

malloc 通常被认为来自 memory allocate(内存分配) 的缩写/组合写法:mal(memory allocate)+ loc(allocate/locate 的缩写形式)。它在早期 C 语言与 Unix 生态中被广泛使用,逐渐固定为标准库接口名称。

相关词 Related Words

文学与经典作品 Literary Works

  • The C Programming Language(Kernighan & Ritchie)——讲解动态内存时会出现 malloc 的用法与示例
  • C Programming: A Modern Approach(K. N. King)——在指针与动态内存章节中使用 malloc
  • Advanced Programming in the UNIX Environment(Stevens & Rago)——系统编程示例中常涉及 malloc 与内存管理
  • The Practice of Programming(Kernighan & Pike)——讨论健壮编程与资源管理时涉及动态分配与释放的典型模式
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   739 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 11ms · UTC 19:13 · PVG 03:13 · LAX 11:13 · JFK 14:13
♥ Do have faith in what you're doing.