简体   繁体   English

napi 中的字符串返回限制

[英]String return limit in napi

I want to port some C++ code to js using napi (node-addon-api).我想使用 napi (node-addon-api) 将一些 C++ 代码移植到 js。 The code is a search handler that returns string.该代码是一个返回字符串的搜索处理程序。 So I wanted to know if there is any size limit in napi in returning strings?所以我想知道在返回字符串时 napi 是否有任何大小限制?

No obvious limit that I know of.我所知道的没有明显的限制。 But if you are going to pass really long strings, the copying from native to Javascript heap would kill the performance.但是,如果您要传递非常长的字符串,则从本机到 Javascript 堆的复制会降低性能。 You may consider use buffer-like types to pass the address of underlying data.您可以考虑使用类似缓冲区的类型来传递底层数据的地址。

Refer to Using Buffers to share data between Node.js and C++ - Scott Frees for detail.有关详细信息,请参阅使用缓冲区在 Node.js 和 C++ 之间共享数据 - Scott Frees

Related N-API: https://nodejs.org/api/n-api.html#n_api_napi_create_buffer相关 N-API: https : //nodejs.org/api/n-api.html#n_api_napi_create_buffer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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