JsSetRuntimeMemoryAllocationCallback
関数ランタイムのメモリ割り当てコールバックを設定する。
シグネチャ
// chakra.dll
#include <windows.h>
JsErrorCode JsSetRuntimeMemoryAllocationCallback(
void* runtime,
void* callbackState, // optional
JsMemoryAllocationCallback allocationCallback
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| runtime | void* | in | メモリ割り当てコールバックを設定する対象のランタイムのハンドル。 |
| callbackState | void* | inoptional | コールバック呼び出し時に渡されるユーザー定義の状態ポインタ。NULL可。 |
| allocationCallback | JsMemoryAllocationCallback | in | メモリ割り当て・解放時に呼ばれるコールバック関数。NULLで解除する。 |
戻り値の型: JsErrorCode
各言語での呼び出し定義
// chakra.dll
#include <windows.h>
JsErrorCode JsSetRuntimeMemoryAllocationCallback(
void* runtime,
void* callbackState, // optional
JsMemoryAllocationCallback allocationCallback
);[DllImport("chakra.dll", ExactSpelling = true)]
static extern uint JsSetRuntimeMemoryAllocationCallback(
IntPtr runtime, // void*
IntPtr callbackState, // void* optional
IntPtr allocationCallback // JsMemoryAllocationCallback
);<DllImport("chakra.dll", ExactSpelling:=True)>
Public Shared Function JsSetRuntimeMemoryAllocationCallback(
runtime As IntPtr, ' void*
callbackState As IntPtr, ' void* optional
allocationCallback As IntPtr ' JsMemoryAllocationCallback
) As UInteger
End Function' runtime : void*
' callbackState : void* optional
' allocationCallback : JsMemoryAllocationCallback
Declare PtrSafe Function JsSetRuntimeMemoryAllocationCallback Lib "chakra" ( _
ByVal runtime As LongPtr, _
ByVal callbackState As LongPtr, _
ByVal allocationCallback As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
JsSetRuntimeMemoryAllocationCallback = ctypes.windll.chakra.JsSetRuntimeMemoryAllocationCallback
JsSetRuntimeMemoryAllocationCallback.restype = wintypes.DWORD
JsSetRuntimeMemoryAllocationCallback.argtypes = [
ctypes.POINTER(None), # runtime : void*
ctypes.POINTER(None), # callbackState : void* optional
ctypes.c_void_p, # allocationCallback : JsMemoryAllocationCallback
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('chakra.dll')
JsSetRuntimeMemoryAllocationCallback = Fiddle::Function.new(
lib['JsSetRuntimeMemoryAllocationCallback'],
[
Fiddle::TYPE_VOIDP, # runtime : void*
Fiddle::TYPE_VOIDP, # callbackState : void* optional
Fiddle::TYPE_VOIDP, # allocationCallback : JsMemoryAllocationCallback
],
-Fiddle::TYPE_INT)#[link(name = "chakra")]
extern "system" {
fn JsSetRuntimeMemoryAllocationCallback(
runtime: *mut (), // void*
callbackState: *mut (), // void* optional
allocationCallback: *const core::ffi::c_void // JsMemoryAllocationCallback
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("chakra.dll")]
public static extern uint JsSetRuntimeMemoryAllocationCallback(IntPtr runtime, IntPtr callbackState, IntPtr allocationCallback);
"@
$api = Add-Type -MemberDefinition $sig -Name 'chakra_JsSetRuntimeMemoryAllocationCallback' -Namespace Win32 -PassThru
# $api::JsSetRuntimeMemoryAllocationCallback(runtime, callbackState, allocationCallback)#uselib "chakra.dll"
#func global JsSetRuntimeMemoryAllocationCallback "JsSetRuntimeMemoryAllocationCallback" sptr, sptr, sptr
; JsSetRuntimeMemoryAllocationCallback runtime, callbackState, allocationCallback ; 戻り値は stat
; runtime : void* -> "sptr"
; callbackState : void* optional -> "sptr"
; allocationCallback : JsMemoryAllocationCallback -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "chakra.dll"
#cfunc global JsSetRuntimeMemoryAllocationCallback "JsSetRuntimeMemoryAllocationCallback" sptr, sptr, sptr
; res = JsSetRuntimeMemoryAllocationCallback(runtime, callbackState, allocationCallback)
; runtime : void* -> "sptr"
; callbackState : void* optional -> "sptr"
; allocationCallback : JsMemoryAllocationCallback -> "sptr"; JsErrorCode JsSetRuntimeMemoryAllocationCallback(void* runtime, void* callbackState, JsMemoryAllocationCallback allocationCallback)
#uselib "chakra.dll"
#cfunc global JsSetRuntimeMemoryAllocationCallback "JsSetRuntimeMemoryAllocationCallback" intptr, intptr, intptr
; res = JsSetRuntimeMemoryAllocationCallback(runtime, callbackState, allocationCallback)
; runtime : void* -> "intptr"
; callbackState : void* optional -> "intptr"
; allocationCallback : JsMemoryAllocationCallback -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
chakra = windows.NewLazySystemDLL("chakra.dll")
procJsSetRuntimeMemoryAllocationCallback = chakra.NewProc("JsSetRuntimeMemoryAllocationCallback")
)
// runtime (void*), callbackState (void* optional), allocationCallback (JsMemoryAllocationCallback)
r1, _, err := procJsSetRuntimeMemoryAllocationCallback.Call(
uintptr(runtime),
uintptr(callbackState),
uintptr(allocationCallback),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // JsErrorCodefunction JsSetRuntimeMemoryAllocationCallback(
runtime: Pointer; // void*
callbackState: Pointer; // void* optional
allocationCallback: Pointer // JsMemoryAllocationCallback
): DWORD; stdcall;
external 'chakra.dll' name 'JsSetRuntimeMemoryAllocationCallback';result := DllCall("chakra\JsSetRuntimeMemoryAllocationCallback"
, "Ptr", runtime ; void*
, "Ptr", callbackState ; void* optional
, "Ptr", allocationCallback ; JsMemoryAllocationCallback
, "UInt") ; return: JsErrorCode●JsSetRuntimeMemoryAllocationCallback(runtime, callbackState, allocationCallback) = DLL("chakra.dll", "dword JsSetRuntimeMemoryAllocationCallback(void*, void*, void*)")
# 呼び出し: JsSetRuntimeMemoryAllocationCallback(runtime, callbackState, allocationCallback)
# runtime : void* -> "void*"
# callbackState : void* optional -> "void*"
# allocationCallback : JsMemoryAllocationCallback -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "chakra" fn JsSetRuntimeMemoryAllocationCallback(
runtime: ?*anyopaque, // void*
callbackState: ?*anyopaque, // void* optional
allocationCallback: ?*anyopaque // JsMemoryAllocationCallback
) callconv(std.os.windows.WINAPI) u32;proc JsSetRuntimeMemoryAllocationCallback(
runtime: pointer, # void*
callbackState: pointer, # void* optional
allocationCallback: pointer # JsMemoryAllocationCallback
): uint32 {.importc: "JsSetRuntimeMemoryAllocationCallback", stdcall, dynlib: "chakra.dll".}pragma(lib, "chakra");
extern(Windows)
uint JsSetRuntimeMemoryAllocationCallback(
void* runtime, // void*
void* callbackState, // void* optional
void* allocationCallback // JsMemoryAllocationCallback
);ccall((:JsSetRuntimeMemoryAllocationCallback, "chakra.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
runtime, callbackState, allocationCallback)
# runtime : void* -> Ptr{Cvoid}
# callbackState : void* optional -> Ptr{Cvoid}
# allocationCallback : JsMemoryAllocationCallback -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t JsSetRuntimeMemoryAllocationCallback(
void* runtime,
void* callbackState,
void* allocationCallback);
]]
local chakra = ffi.load("chakra")
-- chakra.JsSetRuntimeMemoryAllocationCallback(runtime, callbackState, allocationCallback)
-- runtime : void*
-- callbackState : void* optional
-- allocationCallback : JsMemoryAllocationCallback
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('chakra.dll');
const JsSetRuntimeMemoryAllocationCallback = lib.func('__stdcall', 'JsSetRuntimeMemoryAllocationCallback', 'uint32_t', ['void *', 'void *', 'void *']);
// JsSetRuntimeMemoryAllocationCallback(runtime, callbackState, allocationCallback)
// runtime : void* -> 'void *'
// callbackState : void* optional -> 'void *'
// allocationCallback : JsMemoryAllocationCallback -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。const lib = Deno.dlopen("chakra.dll", {
JsSetRuntimeMemoryAllocationCallback: { parameters: ["pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.JsSetRuntimeMemoryAllocationCallback(runtime, callbackState, allocationCallback)
// runtime : void* -> "pointer"
// callbackState : void* optional -> "pointer"
// allocationCallback : JsMemoryAllocationCallback -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t JsSetRuntimeMemoryAllocationCallback(
void* runtime,
void* callbackState,
void* allocationCallback);
C, "chakra.dll");
// $ffi->JsSetRuntimeMemoryAllocationCallback(runtime, callbackState, allocationCallback);
// runtime : void*
// callbackState : void* optional
// allocationCallback : JsMemoryAllocationCallback
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Chakra extends StdCallLibrary {
Chakra INSTANCE = Native.load("chakra", Chakra.class);
int JsSetRuntimeMemoryAllocationCallback(
Pointer runtime, // void*
Pointer callbackState, // void* optional
Callback allocationCallback // JsMemoryAllocationCallback
);
}@[Link("chakra")]
lib Libchakra
fun JsSetRuntimeMemoryAllocationCallback = JsSetRuntimeMemoryAllocationCallback(
runtime : Void*, # void*
callbackState : Void*, # void* optional
allocationCallback : Void* # JsMemoryAllocationCallback
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef JsSetRuntimeMemoryAllocationCallbackNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef JsSetRuntimeMemoryAllocationCallbackDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>);
final JsSetRuntimeMemoryAllocationCallback = DynamicLibrary.open('chakra.dll')
.lookupFunction<JsSetRuntimeMemoryAllocationCallbackNative, JsSetRuntimeMemoryAllocationCallbackDart>('JsSetRuntimeMemoryAllocationCallback');
// runtime : void* -> Pointer<Void>
// callbackState : void* optional -> Pointer<Void>
// allocationCallback : JsMemoryAllocationCallback -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function JsSetRuntimeMemoryAllocationCallback(
runtime: Pointer; // void*
callbackState: Pointer; // void* optional
allocationCallback: Pointer // JsMemoryAllocationCallback
): DWORD; stdcall;
external 'chakra.dll' name 'JsSetRuntimeMemoryAllocationCallback';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "JsSetRuntimeMemoryAllocationCallback"
c_JsSetRuntimeMemoryAllocationCallback :: Ptr () -> Ptr () -> Ptr () -> IO Word32
-- runtime : void* -> Ptr ()
-- callbackState : void* optional -> Ptr ()
-- allocationCallback : JsMemoryAllocationCallback -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let jssetruntimememoryallocationcallback =
foreign "JsSetRuntimeMemoryAllocationCallback"
((ptr void) @-> (ptr void) @-> (ptr void) @-> returning uint32_t)
(* runtime : void* -> (ptr void) *)
(* callbackState : void* optional -> (ptr void) *)
(* allocationCallback : JsMemoryAllocationCallback -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library chakra (t "chakra.dll"))
(cffi:use-foreign-library chakra)
(cffi:defcfun ("JsSetRuntimeMemoryAllocationCallback" js-set-runtime-memory-allocation-callback :convention :stdcall) :uint32
(runtime :pointer) ; void*
(callback-state :pointer) ; void* optional
(allocation-callback :pointer)) ; JsMemoryAllocationCallback
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $JsSetRuntimeMemoryAllocationCallback = Win32::API::More->new('chakra',
'DWORD JsSetRuntimeMemoryAllocationCallback(LPVOID runtime, LPVOID callbackState, LPVOID allocationCallback)');
# my $ret = $JsSetRuntimeMemoryAllocationCallback->Call($runtime, $callbackState, $allocationCallback);
# runtime : void* -> LPVOID
# callbackState : void* optional -> LPVOID
# allocationCallback : JsMemoryAllocationCallback -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。