Skip to content

is it possible to provide an 'unsafe' way to get internal []byte and avoid mem copy? #404

Open
@codingWhat

Description

@codingWhat

What is the issue you are having?

In some scenarios, the data retrieved from the cache will not be modified and could be directly returned.

What is BigCache doing that it shouldn't?

func readEntry(data []byte) []byte {
	length := binary.LittleEndian.Uint16(data[timestampSizeInBytes+hashSizeInBytes:])

	// copy on read
	dst := make([]byte, len(data)-int(headersSizeInBytes+length))
	copy(dst, data[headersSizeInBytes+length:])

	return dst
}

to be --- to recycle the 'dst'

func readEntry(dst, data []byte) []byte {
	length := binary.LittleEndian.Uint16(data[timestampSizeInBytes+hashSizeInBytes:])

	copy(dst, data[headersSizeInBytes+length:])

	return dst
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions