数组是由假定的元素定义的,比如我有像String [] strArray = new String [50]这样的数组; .
现在从50个元素中只分配了一些元素,剩下的都是null,然后我想要分配元素的数量.
像这里只分配了30个元素然后我想要那个数字.
我想用预处理器评论一行:
#define open /##*
#define close */
main()
{
open commented line close
}
Run Code Online (Sandbox Code Playgroud)
当我做$gcc -E filename.c我想到的
/* commented line */
Run Code Online (Sandbox Code Playgroud)
但我明白了
/ * commented line */
Run Code Online (Sandbox Code Playgroud)
这样编译器就会显示错误
为什么会给出不必要的空间?
我真的很困惑为什么它在索引期间一直死于java.lang.OutOfMemoryError,即使它有几GB的内存.
有没有一个根本原因,它需要手动调整配置文件/ jvm参数,而不是只计算可用的内存量并限制自己的内容?除了Solr之外没有其他程序会遇到这种问题.
是的,每次发生此类崩溃时我都可以继续调整JVM堆大小,但这一切都是如此倒退.
以下是最新此类崩溃的堆栈跟踪,以防相关:
SEVERE: java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOfRange(Arrays.java:3209)
at java.lang.String.<init>(String.java:216)
at org.apache.lucene.index.TermBuffer.toTerm(TermBuffer.java:122)
at org.apache.lucene.index.SegmentTermEnum.term(SegmentTermEnum.java:169)
at org.apache.lucene.search.FieldCacheImpl$StringIndexCache.createValue(FieldCacheImpl.java:701)
at org.apache.lucene.search.FieldCacheImpl$Cache.get(FieldCacheImpl.java:208)
at org.apache.lucene.search.FieldCacheImpl.getStringIndex(FieldCacheImpl.java:676)
at org.apache.lucene.search.FieldComparator$StringOrdValComparator.setNextReader(FieldComparator.java:667)
at org.apache.lucene.search.TopFieldCollector$OneComparatorNonScoringCollector.setNextReader(TopFieldCollector.java:94)
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:245)
at org.apache.lucene.search.Searcher.search(Searcher.java:171)
at org.apache.solr.search.SolrIndexSearcher.getDocListNC(SolrIndexSearcher.java:988)
at org.apache.solr.search.SolrIndexSearcher.getDocListC(SolrIndexSearcher.java:884)
at org.apache.solr.search.SolrIndexSearcher.search(SolrIndexSearcher.java:341)
at org.apache.solr.handler.component.QueryComponent.process(QueryComponent.java:182)
at org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:195)
at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:131)
at org.apache.solr.core.SolrCore.execute(SolrCore.java:1316)
at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:338)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:241)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Run Code Online (Sandbox Code Playgroud) 我使用HTML 5 Localstorage开发了应用程序.
在初始化启用HTML 5的应用程序之前,如何创建TABLE并填充10000多行.
请提出一个模式.
海.我正在制作这个简单的字符串类,并想知道是否有更自然的方法.
class Str{
function __construct($str){
$this->value = $str;
$this->length = strlen($str);
..
}
function __toString(){
return $this->value;
}
..
}
Run Code Online (Sandbox Code Playgroud)
所以现在我必须像这样使用它:
$str = new Str('hello kitty');
echo $str;
Run Code Online (Sandbox Code Playgroud)
但是用圆括号看起来并不那么"自然".所以我想知道这样或类似的东西是否可能.
$str = new Str 'hello kitty'; # I dont believe this is possible although this is preferred.
$str = new Str; # get rid of the construct param.
$str = 'value here'; #instead of resetting, set 'value here' to Str::$value??
Run Code Online (Sandbox Code Playgroud)
在第二种方法中,有没有办法可以再次捕获变量bing set而不是重置它,将其设置为Str :: $ value?我已经考虑过了,我最接近的是__destruct方法.但没有办法知道它是如何被摧毁的.这可能还是我在浪费时间?
编译时出错:
raja@raja-desktop:~/socket$ g++ Socket.cpp
Socket.cpp: In member function ‘int Socket::recv(std::string&) const’:
Socket.cpp:135: error: ‘cout’ is not a member of ‘std’
Run Code Online (Sandbox Code Playgroud)
Socket.cpp的来源:
// Implementation of the Socket class.
#include "Socket.h"
#include "string.h"
#include <string.h>
#include <errno.h>
#include <fcntl.h>
Socket::Socket() :
m_sock ( -1 )
{
memset ( &m_addr,
0,
sizeof ( m_addr ) );
}
Socket::~Socket()
{
if ( is_valid() )
::close ( m_sock );
}
bool Socket::create()
{
m_sock = socket ( AF_INET,
SOCK_STREAM,
0 );
if ( ! is_valid() …Run Code Online (Sandbox Code Playgroud) 我用Google搜索并了解了如何使用变量参数.但我想将我的变量参数传递给另一个方法.我得到错误.怎么做 ?
-(void) aMethod:(NSString *) a, ... {
[self anotherMethod:a];
// i m doing this but getting error. how to pass complete vararg to anotherMethod
}
Run Code Online (Sandbox Code Playgroud) 我阅读了很多关于PHP的Restful教程.
(我不想深入探讨为什么我不使用RoR.这是由于团队更熟悉PHP)
因为我们计划将来扩展到API,所以我认为实现Restful Web服务很重要.
我看了很多教程
http://www.gen-x-design.com/archives/create-a-rest-api-with-php/
显然宁静是为web服务.
网页怎么样?它们也可以是RESTFUL吗?
如果答案是否定的,请不要超出这条线并告诉我.谢谢.
我知道让网址看起来像RESTFUL网址就是简单地使用mod_rewrite.但是,我很确定,宁静的架构不仅仅是让网址看起来不错.
例如,我在名为list.php的网页上有一个项目列表.每个项目旁边都有一个删除链接.例如,list.php?id = 1&deleteitem
当有人点击list.php?id = 1&deleteitem链接时,我会回到同一个list.php文件并检查$ _GET中的param deleteitem.
如果检测到,我将根据$ _GET中的参数id从数据库中删除.
之后我将重定向回list.php没有任何参数.
我想知道,我如何使整个流程RESTFUL?
我问,因为在REST中,要删除一些你需要使用HTTP请求方法(DELETE).
很明显,在我的链接中,它们都很简单 <a href="list.php?id=1&deleteitem">Delete</a>
请赐教.
我的编程并不那么强大,如果给出的建议尽可能地成为外行,那将是很好的.
谢谢.
编辑
我有2个跟进问题.
问题1)由于这是一个带分页的项目列表,如果我想让它成为RESTful,URL会是什么样子?
问题2)因为我在列表中的每个项目旁边放置DELETE链接,我现在明白了,我应该使用
<form method="POST">
<input type=hidden name="_method" value="delete">
<input type="submit" >
</form>
Run Code Online (Sandbox Code Playgroud)
代替.
但表格应该张贴到哪里?项目网址?/项目/ {项目-ID}
但是我想回到这个列表页面,在成功删除数据库中的行后显示成功消息.
当我使用成功消息刷新此列表页面时,我还想避免弹出消息.
如果我发回这个list.php网址,那么它不是RESTful是吗?因为下面的答案我告诉我每个项目都是需要自己网址的资源.
请赐教.谢谢.
我打破左锁骨,左手完全固定,所以我只能用右手打字(感谢上帝,我是右撇子).你可以想象我的打字速度大大降低了.
任何人都可以建议一种方法来克服这个障碍,可能是一些emacs模式或Visual Studio插件,专门为只能用一只手打字的人设计?
我不是大鼠用户,所以欢迎任何建议如何简化我与OS(Linux,Windows)的交互.