在Java中填充预先分配的ByteBuffer的最快方法是什么?
我首先使用"assignedirect"设置ByteBuffer的大小,这只需要完成一次.在我需要尽可能快地填充它(循环它)后,新数据以每5ms的形式到达一个byte []数组,并且没有占用内存,因为我已经预先分配了ByteBuffer.目前我使用".put()"指令,在我的系统中需要大约100ms才能完成.还有另一种填充ByteBuffer的方法吗?".wrap()"函数运行得更快而不重新分配数组吗?
我有一个类似于的简单数据集类:
class DataSet {
private String value;
private String additionalValue;
public DataSet(String value, String additionalValue) {
this.value = value;
this.additionalValue = additionalValue;
}
public String getAdditionalValue() {
return this.additionalValue;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我创建了一个ArrayList<DataSet>并添加了一个新元素DataSet("Value1", null).
现在在某些时候我需要检查有值的条目"Value1"是否有additionalValue,如果有,它是什么.
我做了一个简单的循环检查value.equals("Value1") == true,然后我这样做:
if (element.getAdditionalValue() != null) {
return element.getAdditionalValue();
}
Run Code Online (Sandbox Code Playgroud)
但是,只要它到达if语句,它就会抛出一个错误,表示值为null.我怎样才能让这个它不会引发错误,只是跳过的return声明,如果additionalValue是null?
编辑:
但问题是元素不能null在additionalValue它通过element.getValue.equals("Value1")条件时检查它.
for (DataSet element : dataSet) { …Run Code Online (Sandbox Code Playgroud) 我最近卸载jre7并安装了jre6,因为我的项目需要它.但现在我的程序显示类路径错误.如何在Eclipse中更改类路径?
错误是:
归档:C:/ Program Files/Java/jdk1.7.0_05/lib/tools.jar由类路径引用,不存在.
这是交易.如果我将代码保留为glGenBuffers(1,vertexBuffers),代码编译就可以了.但是,我认为它应该是2,因为vertexBuffers的大小为2.
我错过了什么吗?
代码如下:
-(void)drawRect:(NSRect)dirtyRect
{
// get program ID for shader program
GLuint programID = [self loadShaders];
// get new dimensions
NSSize dim = [self frame].size;
// clear the background with color
glClearColor(0.0, 0.0, 0.0, 0.4);
glDepthRange(0.1, 100.0);
glViewport(0, 0, dim.width, dim.height);
glClear(GL_COLOR_BUFFER_BIT);
// vertex data
GLfloat vertexPositionData[] = {-dim.width/2, -dim.height/2, 0.0, 5.0,
dim.width/2, -dim.height/2, 0.0, 5.0,
0.0, dim.height/2, 0.0, 5.0};
GLfloat vertexColorData[] = {1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.5, 0.0, 0.0, 1.0, 0.5};
GLfloat scaleMatrixData[] = {1/(dim.width/2), …Run Code Online (Sandbox Code Playgroud) 我试图将我用Eclipse编写的项目移动到另一台计算机上.我尝试声明正确的工作区,但项目没有出现在Eclipse中.
有没有办法传输整个项目,还是我必须用它的包重建项目并只传输.java文件?
在Java中,我们通常使用一个流对象来包装另一个流类以提高效率。例如:
Object obj = new MyClass();
try {
FileOutputStream fos = new FileOutputStream("test.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(obj);
oos.flush();
} catch(IOException e) {
e.printStackTrace();
} finally {
fos.close();
oos.close();
}
Run Code Online (Sandbox Code Playgroud)
我用来ObjectOutputStream包裹FileOutputStream。类似的情况是使用BufferedReader包装InputStreamReader。
我的问题是如何按顺序正确关闭fos和oos。应该先关闭哪一个?或者只需要关闭其中一个。通常关闭两个流都会起作用,但我对这种方式感到不舒服,因为我不理解语义。我只是使用 close 方法来关闭所有内容,而我不知道为什么不直接 closefos或oos。
我想渲染一个索引的几何体。因此,我有一堆顶点和相关的顺序索引。我glDrawElements()用来渲染2个四边形,如下所示。现在,我知道可以glColorPointer()用于指定每个顶点的颜色了。我的问题是:我可以为每个图元指定颜色吗?如果是,那我应该如何为这个索引的几何图形做呢?
static GLint vertices[] ={0,0,0,
1,0,0,
1,1,0,
0,1,0,
0,0,1,
0,1,1};
static GLubyte indices[]={0,1,2,3,
0,3,5,4}
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEXARRAY);
//glColorPointer(3, GL_FLOAT,0,colors);
glVertexPointer(3,GL_INT,0,vertices);
glDrawElements( GL_QUADS, sizeof( indices ) / sizeof( GLubyte ), GL_UNSIGNED_BYTE, indices );
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,当我按下按钮时,我需要找到键盘隐藏操作.为此,我需要找到该按钮的密钥代码,但是,我不知道按钮的密钥代码.谁能告诉我这个按钮的键码是什么?

这是我的代码:
public boolean dispatchKeyEventPreIme(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
hide.setVisibility(View.INVISIBLE);
return true;
}
return super.dispatchKeyEvent(event);
}
Run Code Online (Sandbox Code Playgroud)
这是适用于后退按钮的代码,但不适用于隐藏键盘按钮.
我对这被认为是一种好习惯感到困惑 - 这种决策语言是否依赖?假设我有以下Java代码:
public class Stack {
public Integer pop() {
if (isEmpty()) return null; // or some exception maybe?
// else get and return the top item in the stack.
};
}
}
Run Code Online (Sandbox Code Playgroud)
该pop方法的客户端需要一些Integer值,那么让客户端知道堆栈为空的最佳方法是什么?
uses-feature 用于以下方式:
<uses-feature
android:name="string"
android:required=["true" | "false"]
android:glEsVersion="integer" />
Run Code Online (Sandbox Code Playgroud)
android:required和的用途是android:glEsVersion什么?
java ×6
android ×2
eclipse ×2
opengl ×2
arrays ×1
bytebuffer ×1
class ×1
classpath ×1
cocoa ×1
hide ×1
keycode ×1
nsopenglview ×1
null ×1
performance ×1
project ×1
refactoring ×1
stream ×1