小编Joh*_*ter的帖子

C++使用关键字

这两种using关键字用法有什么区别:

using boost::shared_ptr;
Run Code Online (Sandbox Code Playgroud)

using namespace boost;
Run Code Online (Sandbox Code Playgroud)

c++ namespaces using-declaration

17
推荐指数
1
解决办法
8013
查看次数

使用RecursiveArrayIterator时如何更改数组键和值?

我怀疑我在这里做了些蠢事,但我对SPL的一个简单问题感到困惑:

如何使用RecursiveArrayIterator/RecursiveIteratorIterator修改数组的内容(本例中的值)?

使用以下测试代码,我可以使用getInnerIterator()offsetSet()更改循环内的值,并在循环中转储已修改的数组.

但是当我离开循环并从迭代器转储数组时,它又回到了原始值.发生了什么?

$aNestedArray = array();
$aNestedArray[101] = range(100, 1000, 100);
$aNestedArray[201] = range(300, 25, -25);
$aNestedArray[301] = range(500, 0, -50);

$cArray = new ArrayObject($aNestedArray);
$cRecursiveIter = new RecursiveIteratorIterator(new RecursiveArrayIterator($cArray), RecursiveIteratorIterator::LEAVES_ONLY);

// Zero any array elements under 200  
while ($cRecursiveIter->valid())
{
    if ($cRecursiveIter->current() < 200)
    {
        $cInnerIter = $cRecursiveIter->getInnerIterator();
        // $cInnerIter is a RecursiveArrayIterator
        $cInnerIter->offsetSet($cInnerIter->key(), 0);
    }

    // This returns the modified array as expected, with elements progressively being zeroed
    print_r($cRecursiveIter->getArrayCopy()); …
Run Code Online (Sandbox Code Playgroud)

php spl iterator arrayiterator

16
推荐指数
3
解决办法
4801
查看次数

php/symfony/doctrine内存泄漏?

我使用symfony 1.4和doctrine 1.2将对象批量插入数据库时​​出现问题.

我的模型有一种称为"扇区"的对象,每个对象都有几个"Cupo"类型的对象(通常范围从50到200000).这些物体非常小; 只是一个短标识符字符串和一个或两个整数.每当用户创建一组扇区时,我需要自动将所有这些"Cupo"实例添加到数据库中.如果出现任何问题,我正在使用一个学说交易来回滚所有内容.问题是我只能在php耗尽内存之前创建大约2000个实例.它目前有128MB的限制,应该足以处理使用少于100个字节的对象.我已经尝试将内存限制增加到512MB,但是php仍然崩溃,但这并没有解决问题.

这是错误:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 71 bytes) in /Users/yo/Sites/grifoo/lib/vendor/symfony/lib/log/sfVarLogger.class.php on line 170
Run Code Online (Sandbox Code Playgroud)

这是代码:

public function save($conn=null){

    $conn=$conn?$conn:Doctrine_Manager::connection();

    $conn->beginTransaction();


    try {
        $evento=$this->object;


        foreach($evento->getSectores() as $s){

            for($j=0;$j<$s->getCapacity();$j++){

                $cupo=new Cupo();
                $cupo->setActivo($s->getActivo());
                $cupo->setEventoId($s->getEventoId());
                $cupo->setNombre($j);
                $cupo->setSector($s);

                $cupo->save();

            }
        }

        $conn->commit();
        return;
    }
    catch (Exception $e) {
        $conn->rollback();
        throw $e;
    }
Run Code Online (Sandbox Code Playgroud)

再一次,这个代码适用于少于1000个对象,但任何大于1500的代码都会失败.谢谢您的帮助.

php memory-leaks doctrine symfony1

16
推荐指数
2
解决办法
1万
查看次数

为什么在python中没有执行flow控制语句?

有没有一个很好的理由为什么在python中没有do while flow控制语句?

人们为什么要编写whilebreak明确?

python

16
推荐指数
2
解决办法
2511
查看次数

在个人网站上使用谷歌Chrome的OmniBox [TAB]功能?

我认为标题解释了这一切,但我还是更深入地研究了我的问题:

如何在我的网站上使用Chrome的Omnibox [TAB]功能?

由于许多用户要求我在网站上实现该功能,我对OpenSearchDescription进行了研究,并且在使用FireFox和IE7/IE8搜索栏时非常成功.

然而,实施对Chrome Omnibox [TAB]功能并不起作用.

你能帮帮我吗?

我的OSD.xml代码:

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
                       xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>MySite</ShortName>
<Description>My Site</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16" type="image/x-icon">http://MySite.com/favicon.ico</Image>
<Url type="application/x-suggestions+json" method="GET"
     template="http://ff.search.yahoo.com/gossip?output=fxjson&amp;command={searchTerms}" />
<Url type="text/html" method="POST" template="http://MySite.com/query.php">
  <Param name="sString" value="{searchTerms}"/>
</Url>
<Url type="application/x-suggestions+json" template="suggestionURL"/>
<moz:SearchForm>http://www.MySite.com</moz:SearchForm>
</OpenSearchDescription>
Run Code Online (Sandbox Code Playgroud)

这是我页面上osd文件的链接:

<link rel="search" type="application/opensearchdescription+xml" title="MySite" href="/opensearch.xml" />
Run Code Online (Sandbox Code Playgroud)

google-chrome searching-xml opensearch

14
推荐指数
2
解决办法
1万
查看次数

使用C++扩展PHP?

我有一个用PHP编写的性能密集型例程,我想将其移植到C++以提高性能.有没有办法用PHP编写插件或扩展或其他什么东西?没有手动编辑实际的PHP源代码?

php c++ plugins php-extension

13
推荐指数
2
解决办法
9800
查看次数

MySQL数据库的英文单词?

我正在寻找我正在处理的密码应用程序的英语词典单词列表.理想情况下,列表可以很容易地插入到mysql数据库中.有什么建议?

php mysql dictionary

12
推荐指数
3
解决办法
5793
查看次数

为什么在引用值上调用函数(例如strlen,count等)这么慢?

我刚刚在PHP中发现了一些非常奇怪的东西.

如果我通过引用将变量传递给函数,然后在其上调用函数,那就非常慢.

如果循环遍历内部函数调用且变量很大,则它可能比通过值传递变量慢许多个数量级.

例:

<?php
function TestCount(&$aArray)
{
    $aArray = range(0, 100000);
    $fStartTime = microtime(true);

    for ($iIter = 0; $iIter < 1000; $iIter++)
    {
        $iCount = count($aArray);
    }

    $fTaken = microtime(true) - $fStartTime;

    print "took $fTaken seconds\n";
}

$aArray = array();
TestCount($aArray);
?>
Run Code Online (Sandbox Code Playgroud)

这在我的机器上运行大约需要20秒(在PHP 5.3上).

但是,如果我将函数更改为按值传递(即function TestCount($aArray)代替function TestCount(&$aArray)),则它会在大约2毫秒内运行 - 实际上要快10,000倍!

对于其他内置函数(例如strlen用户定义的函数)也是如此.

这是怎么回事?

php performance reference pass-by-reference

12
推荐指数
1
解决办法
1446
查看次数

在网站中启用"Tab to search"

我正在寻找一种方法在我的网站上启用谷歌浏览器的"标签搜索"功能,有没有人有这方面的经验?

谷歌没有为我提供足够的信息,我猜这个社区更快.

非常感激

browser google-chrome opensearch

12
推荐指数
1
解决办法
3663
查看次数

如何检测单击jQuery UI对话框的(X)关闭按钮,与dialogclose/dialogbeforeclose事件分开?

我希望能够检测到被点击的jQuery UI对话的(x)关闭按钮,但我不想使用dialogclose/ dialogbeforecloseevents(因为我相信无论对话框是如何关闭的,它们都会触发).

我试过了$(".ui-dialog-titlebar-close").live("click"),但这似乎不起作用.

我怎样才能做到这一点?

示例代码:(对话框关闭时,调试器不会启动).

<!DOCTYPE html>
<html>
<head>
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.js"></script>

  <script>
  $(document).ready(function() {
    $("#dialog").dialog();

    $(".ui-dialog-titlebar-close").live("click", function() { 
        debugger; // ** clicking the close button doesn't get to here.**
        });
  });
  </script>
</head>

<div id="dialog" title="Dialog Title">I'm in a dialog</div>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

jquery dialog jquery-ui

12
推荐指数
2
解决办法
2万
查看次数