简体   繁体   中英

Is there a Macro for a Function Pointer? UE4 C++

I made a function pointer in ue4 c++ and dont know which macro i can/should use for the pointer in the header file. (things like UPROPERTY() or UFUNCTION())

why i even want to use a macro? Because of the garbage collection and, as far as i know, the gb only works when the variable/function has a macro.

btw, is a function pointer call as performant as a normal function call?

header.h Code:

typedef void (AWeaponGun::*FireTypeFunctionPtr)(void);    
FireTypeFunctionPtr PtrFireType;
    
UFUNCTION()
void FireLineTrace();

file.cpp Code:

void AWeaponGun::BeginPlay()
{
    PtrFireType = &AWeaponGun::FireLineTrace;
}

void AWeaponGun::Tick(float DeltaTime)
{
    (this->*PtrFireType)();
}

Functions and your function pointer are not allocated and deallocated so you don't need the garbage collector in this case, and thus you don't need any UE4 macro (...if you only consider the garbage collector).

As for performance, the function pointer is most probably slightly less performant as it adds one more variable and needs additional instructions to reach the function. But the compiler might be able to optimize some of the differences in some cases. You would need to check the assembly code created in both cases to be sure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM