Sds malloc
- 構文
- void *sds_malloc (size_t bytes);
- 機能
- メモリを割り当てる。
- 引数
-
- bytes : 割り当てるバイトサイズ
- 戻り値
- メモリ領域へのポインター、割り当てできなかった場合は NULL。
- サンプル
struct resbuf pRbBuf;
char *buff = NULL;
// カレントレイヤ名を取得
if (sds_getvar("CLAYER", &pRbBuf) == RTNORM)
{
// リザルトバッファの戻り値テスト
if (pRbBuf.restype == RTSTR)
{
// メモリを割り当て
buff = (char *)sds_malloc((sizeof(char) * strlen(pRbBuf.resval.rstring)) + 1);
strcpy(buff, pRbBuf.resval.rstring);
sds_alert(buff);
sds_free(pRbBuf.resval.rstring); // ダイナミックに割り当てられた文字列のバッファを解放
sds_free(buff); // バッファの開放
}
else{
sds_alert("値が文字じゃありません");
}
}
else
{
sds_alert("レイヤ名の取得に失敗しました");
}
return (RSRSLT);
関連事項