zoukankan      html  css  js  c++  java
  • php扩展开发笔记1

    内存分配

    为了避免写的不好的扩展浪费内存,ZE通过标记实现内部内存管理来表示持有。

    persistent allocation 意味着分配的内存比一个页面请求持续更长时间。

    non-persistent allocation 无论释放函数有没有调用,将被释放在为它分配内存的请求结束后。

    理论上,一个依赖ZE在请求结束自动释放non-persistent内存的扩展是不被推荐的。内存分配将会保留更长时间,资源相关的内存不会像正常关机那样,它缺乏清理烂摊子的经验。

    下面是几种内存分配的比较:

    TraditionalNon-PersistentPersistent
    malloc(count)
    calloc(count, num)
    emalloc(count)
    ecalloc(count, num)
    pemalloc(count, 1)*
    pecalloc(count, num, 1)
    strdup(str)
    strndup(str, len)
    estrdup(str)
    estrndup(str, len)
    pestrdup(str, 1)
    pemalloc() & memcpy()
    free(ptr) efree(ptr) pefree(ptr, 1)
    realloc(ptr, newsize) erealloc(ptr, newsize) perealloc(ptr, newsize, 1)
    malloc(count * num + extr)** safe_emalloc(count, num, extr) safe_pemalloc(count, num, extr)
    The pemalloc() family include a ‘persistent’ flag which allows
    them to behave like their non-persistent counterparts.
       For example:
    emalloc(1234) is the same as pemalloc(1234,
    0)

    ** safe_emalloc() and (in PHP 5) safe_pemalloc()
    perform an additional check to avoid integer overflows

     

    算得上是

  • 相关阅读:
    【Spring Cloud】异常记录
    目录
    java8 语言特性
    Java 8 并发编程
    Spring Boot系列(四) Spring Cloud 之 Config Client
    找到字符串中最长的非重复子串
    Spring Boot系列(四) Spring Boot 之验证
    链表两数相加(add two numbers)
    找到数组中和为给定值的两个数
    Spring Boot系列(三) Spring Boot 之 JDBC
  • 原文地址:https://www.cnblogs.com/zaric/p/2694388.html
Copyright © 2011-2022 走看看