首页 \ 问答 \ JNI直接缓冲区。(JNI direct buffers. Who is responsible for native buffer freeing?)

JNI直接缓冲区。(JNI direct buffers. Who is responsible for native buffer freeing?)

假设一方面我们有一个用env->NewDirectByteBuffer()创建的直接字节缓冲区。 另一方面,我们有类似的直接缓冲区,但是使用ByteBuffer.allocateDirect()创建。 显然,这两个对象都应该由JVM以相同的方式管理,包括后台本机缓冲区的管理,第一种情况是由用户提供,第二种情况是由JVM从本机堆分配的。

当然,JVM必须在第二个对象的GC期间释放后备缓冲区(用ByteBuffer.allocateDirect()实例化)。

我的问题是:JVM是否会尝试在第一个对象的GC期间解除分配缓冲区(用env->NewDirectByteBuffer()实例化)?

PS我也没有在JNI医生处找到明确的答案。 最有用的信息是http://www.ibm.com/developerworks/library/j-nativememory-linux/index.html

Direct ByteBuffer对象自动清理它们的本机缓冲区,但只能作为Java堆GC的一部分来执行 - 因此它们不会自动响应本机堆上的压力。

所以看起来JVM会在GC传递期间释放后备缓冲区,但是没有任何关于deallocator的提及。 是free()或其他东西。


Assume in one hand we have a direct byte buffer created with env->NewDirectByteBuffer(). In other hand we have similar direct buffer, but created with ByteBuffer.allocateDirect(). Obviously both these objects should be managed by JVM in the same manner, including management of the backing native buffer, which in first case was provided by user, and in second case was allocated by JVM from native heap.

Of course JVM must free backing buffer during GC'ing of the second object (instantiated with ByteBuffer.allocateDirect()).

And my question: Will JVM try to deallocate buffer during GC'ing of the first object (instantiated with env->NewDirectByteBuffer()) ?

P.S. I've not found clear answer neither at JNI docs neither at SO. The most helpful info was here http://www.ibm.com/developerworks/library/j-nativememory-linux/index.html :

Direct ByteBuffer objects clean up their native buffers automatically but can only do so as part of Java heap GC — so they do not automatically respond to pressure on the native heap.

So it seems like JVM will free backing buffers during GC pass, but there is no any mentions about deallocator. Is it plain free() or something else.


原文:https://stackoverflow.com/questions/35363486
更新时间:2021-06-11 20:06

最满意答案

nl2br()使用其输入中存在的任何行结尾。 如果您不想在输出中看到\r\n ,请在传入之前将其转换为\n

这个函数的文档中没有明确说明,但它的描述很重要,它的内容是:强调我的:

返回所有换行符之前插入 '<br />''<br>'字符串( \r\n\n\r \n\n\r \n )。

通过测试证实了这一点。


nl2br() uses whatever line endings were present in its input. If you don't want to see \r\n in the output, convert it to \n before you pass it in.

This isn't explicitly stated in the documentation for this function, but it's implied heavily by the description, which reads (emphasis mine):

Returns string with '<br />' or '<br>' inserted before all newlines (\r\n, \n\r, \n and \r).

And it's borne out by testing.

相关问答

更多
  • 问题在于,\ r和\ n分别以“\”“r”和“\”“\ n”存储在数据库中。 它们不作为回车符或新行字符存储,而是以字母后跟斜杠字符存储。 当你调用nl2br() ,它正在寻找新的行字符,而不是它的文本表示。 希望这是有道理的。 您可以使用正则表达式( preg_replace )或str_replace来替换它们。 但问题可能是由于数据如何插入数据库造成的。 例如: $string = str_replace('\n', "\n", $string); $string = str_replace('\r' ...
  • 没有什么内置的,但是,你可以创建类似的东西来构建你自己: public static String nl2br (String str) { return str.replaceAll("\n", "
    "); } // Use this way: nl2br("Hello\nworld"); // This will return "Hello
    world"; There's nothing built-in, however, you can create something s ...
  • 我怀疑这是因为发送的字符字面上'\ n'不是换行符。 GET请求应该类似于First+line%0ASecond+line ; 如果您无法更改请求,可以更改替换以转义斜杠: print str_replace(array("\\r\\n", "\\r", "\\n"), "
    ", $name); I suspect this is because the characters sent are literally '\n' not a newline. The GET request should ...
  • nl2br()使用其输入中存在的任何行结尾。 如果您不想在输出中看到\r\n ,请在传入之前将其转换为\n 。 这个函数的文档中没有明确说明,但它的描述很重要,它的内容是:强调我的: 返回在所有换行符之前插入 '
    '或'
    '字符串( \r\n , \n\r \n , \n和\r \n )。 通过测试证实了这一点。 nl2br() uses whatever line endings were present in its input. If you don't want to see \r\ ...
  • $message_var_1 = 'test1 \r\n test2 \r\n test3'; PHP仅在" ,而不是在...内"解析\r和\n 。所以nl2br不适用于此处。 $message_var_1 = "test1 \r\n test2 \r\n test3"; $message = '
    '.nl2br($message_var_1).'
    '; 这应该有效。 $message_var_1 = 'test1 \r\n test2 \r\n t ...
  • 在将字符串传递给nl2br()之前,您可以将它们转换为各自的转义序列,如下所示: $description = nl2br(str_replace('\\r\\n', "\r\n", $description)); 但是,首先在数据库中执行的文字转义是什么? You could translate them into their respective escape sequences before passing the string through nl2br(), like this: $descri ...
  • 在nl2br_lose中: `return preg_replace("//", '', $string); //removes
    ,
    ,
    ,
    ` 当然,为了简单起见,它交换了可读性。 另一种选择是写一个函数来调用而不是nl2br: function stripnl2br($string) {return str_replace("\n", '', nl2br($string));} in nl2br_lose: `return preg_rep ...
  • 为什么不在调用nl2br之前更换多个新线路? 如果你想让他们在帖子中只使用一个新行: $firstPos = strpos($text, "\n"); if ($firstPos !== false) { $text = substr_replace(array("\r","\n"),'', $text, $firstPos + 1); } $text = nl2br($text); 如果你想让他们只使用一个连续的新行(允许foo\nbar\nbaz ): $text = preg_replace ...
  • 我不确定我理解你用这个功能想要完成什么。 首先,在每个新行中插入HTML中断,然后删除除中断之外的所有标记。 首先剥离标签然后插入HTML换行符不是更明智吗? public function eliminateTags($msg) { $decodeHTML = htmlspecialchars_decode($msg); $withoutTags = strip_tags($decodeHTML); $setBreaks = nl2br($withoutTags); re ...
  • "\n"与'\n' ! 这是你的基本问题。 你不是要试图取代你的想法 "\n"将转换为换行符或ASCII 13 '\n'是字符\然后是字符n $ba='hi\r\nhello'; $ba=str_replace('\r\n','
    ',$ba); echo $ba; // hi
    hello 使用正则表达式: as \是一个转义字符,你需要将它加倍: $ba=preg_replace('#\\\r\\\n|\\\r|\\\n#','
    ',$ba); "\n" is not the sam ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。