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 withByteBuffer.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
最满意答案
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\ ... -
PHP nl2br()基本功能(PHP nl2br() basic function)[2022-10-23]
$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).' -
在将字符串传递给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中只允许一个br(Allow only one br in nl2br)[2024-02-28]
为什么不在调用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 ...
-
在PHP和CodeIgniter中使用nl2br不打印新行(New line not printing by using nl2br in PHP and CodeIgniter)[2022-04-15]
"\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 ...