Skip to content

bug fix: adding data() function to return pointer to data of span - #302

Merged
chillenzer merged 1 commit into
alpaka-group:devfrom
saeedelsayed:dev
May 20, 2026
Merged

bug fix: adding data() function to return pointer to data of span#302
chillenzer merged 1 commit into
alpaka-group:devfrom
saeedelsayed:dev

Conversation

@saeedelsayed

Copy link
Copy Markdown
Contributor

No description provided.

@saeedelsayed

saeedelsayed commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

I had this error when trying to compile the native-cuda example:

/mallocMC/examples/native-cuda/source/main.cu(91): error: class "mallocMC::span<uint64_t>" has no member "data" memoryManager.free(a.data()); ^ /home/saids/mallocMC/examples/native-cuda/source/main.cu(92): error: class "mallocMC::span<uint64_t>" has no member "data" memoryManager.free(b.data()); ^

Please note that the begin() function is doing the same functionality as data() and can be used instead. However, data() is more expressive.

@chillenzer

Copy link
Copy Markdown
Contributor

Please note that the begin() function is doing the same functionality as data() and can be used instead. However, data() is more expressive.

That's not quite true: They are identical on the implementation level but they have different semantics (by convention), compare begin and data. The former returns an iterator, the latter a pointer to the underlying data. As a C++ happens to fulfill the corresponding iterator concept, returning that pointer is semantically valid but not quite necessary for begin to have the correct semantics.

@chillenzer chillenzer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! Thank you!

@chillenzer
chillenzer merged commit 4bb2bf8 into alpaka-group:dev May 20, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants