Skip to content

Return a pointer in Engine creation #54

@diegolatorre16

Description

@diegolatorre16

Hi, in the file engine.go you have:

func NewEngine(config EngineConfig) Engine {
	var newEngine = engine{}
	var loaderHandlerIdPtr C.uintptr_t
	var customNodeHandlerIdPtr C.uintptr_t

	if config.Loader != nil {
		newEngine.loaderHandler = cgo.NewHandle(wrapLoader(config.Loader))
		loaderHandlerIdPtr = C.uintptr_t(newEngine.loaderHandler)
		newEngine.loaderHandlerIdPtr = &loaderHandlerIdPtr
	}

	if config.CustomNodeHandler != nil {
		newEngine.customNodeHandler = cgo.NewHandle(wrapCustomNodeHandler(config.CustomNodeHandler))
		customNodeHandlerIdPtr = C.uintptr_t(newEngine.customNodeHandler)
		newEngine.customNodeHandlerIdPtr = &customNodeHandlerIdPtr
	}

	newEngine.enginePtr = C.zen_engine_new_golang(&loaderHandlerIdPtr, &customNodeHandlerIdPtr)
	return newEngine
}

Is there any specific reason for returning a value instead of a pointer? I think we usually create just one instance of the engine and reuse it throughout the project, so heap allocations aren't a problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions