### malloc分配內存
- malloc用來分配空間,然后返回一個指針,指向堆上新分配的空間
- 使用malloc時需要引入頭文件stdlib.h
- malloc需要知道數據類型所占的字節,通常配合sizeof使用,例如: swServer *p = malloc(sizeof(struct swServer));
```c
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
typedef struct island {
char *name;
struct island *next;
} island;
void display(island *island)
{
for (; island != NULL; island = island->next) {
printf("name: %s\n", island->name);
}
}
island* create(char *name)
{
island *i = malloc(sizeof(island));
i->name = strdup(name); /* 記得要釋放strdup在堆上創建的空間 */
i->next = NULL;
return i;
}
void release(island *start)
{
island *i = start;
island *next = NULL;
while (i != NULL) {
next = i->next;
free(i->name); /* 釋放strdup創建的name字段 */
free(i);
i = next;
}
}
int main()
{
island *start = NULL;
island *i = NULL;
island *next = NULL;
char name[80];
for (; fgets(name, 80, stdin) != NULL; i = next) {
next = create(name);
if (start == NULL) {
start = next;
}
if (i != NULL) {
i->next = next;
}
}
display(start);
release(start);
}
```
- php
- 編譯安裝
- 基本概念
- 垃圾回收機制
- 生命周期
- zval底層實現
- c擴展開發
- gdb調試工具
- 自定義擴展簡單demo
- 鉤子函數
- 讀取php.ini配置
- 數組
- 函數
- 類
- yaf擴展底層源碼
- swoole擴展底層源碼
- memoryGlobal內存池
- swoole協程使用記錄
- 單點登錄sso原理
- compser使用
- session實現機制
- c & linux
- gcc
- 指針
- 結構體,聯合和位字段
- 宏定義井號說明
- printf家族函數和可變參數
- 共享函數
- 靜態庫和動態庫
- makefile自動化構建
- 信號一
- 信號二
- inotify監控文件事件
- socket編程
- 簡介
- UNIX DOMAIN
- Internet DOMAIN
- TCP/IP
- 文件IO多路復用
- 內存管理
- 進程組,會話和控制終端
- daemon守護進程
- 多進程
- 多線程
- 常用進制轉換
- go
- 入門知識
- 字節和整數裝換
- python
- redis
- 應用場景
- 消息隊列
- 熱點數據
- 掃碼登錄
- 訂閱發布
- 次數限制
- 搶購超賣
- 持久化機制
- mysql
- 工作流程
- MyISAM和InnoDB區別
- 用戶和權限管理
- 執行計劃
- sql優化
- 事務和鎖
- 慢查詢日志
- case...when...then...end用法
- sql
- 參考
- linux
- 內核參數優化
- 防火墻設置
- docker
- docker入門知識
- 算法
- 多維數組合
- DFA算法
- 紅包金額分配