我对C#很新,所以请耐心等待.我正在读取(使用FileStream)数据(固定大小)到小数组,处理数据然后再读取,依此类推到文件末尾.
我想过用这样的东西:
byte[] data = new byte[30];
int numBytesToRead = (int)fStream.Length;
int offset = 0;
//reading
while (numBytesToRead > 0)
{
fStream.Read(data, offset, 30);
offset += 30;
numBytesToRead -= 30;
//do something with the data
}
Run Code Online (Sandbox Code Playgroud)
但是我检查了文档及其示例,他们表示上述读取方法的返回值为:
"类型:System.Int32读入缓冲区的总字节数.如果该字节数当前不可用,则可能小于请求的字节数,如果到达流末尾则为零."
它们目前无法使用是什么意思,这在读取少量数据时是否真的会发生,或者这只是大量数据?如果只是为了大,大约有多大,因为我也会在其他地方阅读更大的块.如果这种情况随时可能发生,我应该如何更改代码,以便代码仍能有效执行?
谢谢你的时间和答案.
所以我有这个:
var str = A123B234C456;
Run Code Online (Sandbox Code Playgroud)
我需要将它拆分为逗号分隔的块以返回如下内容:
A,123,B,234,c,456
Run Code Online (Sandbox Code Playgroud)
我认为正则表达式是最好的,但我一直卡住,基本上我试图做一个字符串替换,但你不能在第二个参数中使用正则表达式
我希望保持简单和干净,并做这样的事情,但它不起作用:
str = str.replace(/[\d]+/, ","+/[\d]+/);
Run Code Online (Sandbox Code Playgroud)
但在现实世界中,这太简单了.
有什么想法吗?提前致谢!
我正在尝试重塑数据帧:
目前它看起来像这样:
ID | Gender |A1 | A2 | A3 | B1 | B2 | B3
ID_1 | m | 3 | 3 | 3 | 2 | 3 | 2
ID_2 | f | 1 | 1 | 1 | 4 | 4 | 4
Run Code Online (Sandbox Code Playgroud)
我希望有类似的东西:
ID | Gender | A1 | A2 | A3
ID_1 | m | 3 | 3 | 3 <- this would be columns A1 - A3 for ID 1
ID_1 | m | …Run Code Online (Sandbox Code Playgroud) 我目前正在使用C API调用luaL_loadstring()来加载一个块,但是这个调用没有一种命名块的方法.
是否有一种方法可以在加载后命名一个块?
或者,我看到该lua_load()函数采用chunkname参数,但我没有找到如何使用它的任何示例:如何luaL_loadstring()用lua_load()?替换调用?
好的,基本上在我的游戏中,世界是由图块组成的,图块被分成块(50x50 图块,图块为 16x16),因此整个世界不会加载到内存中。这些块被保存到文件中,并且仅加载需要的块(屏幕上的块和屏幕每一侧(顶部、左侧、底部、右侧)的 1 个块),其他块则被卸载等等。这一切都有效不过很好,当加载实际包含图块的块时,游戏逻辑会冻结相当多的时间(你知道加载文件吗?),基本上我的问题是如何使我当前的方法更快,所以几乎没有明显的滞后?
基本上每个块只包含一个 2D 字节数组,包含图块类型而不是实际的图块类,并且该字节数组保存到文件中以供稍后加载。我的块加载/保存功能:
保存:
public void SaveChunk(int cx, int cy)
{
String chunkname = "";
chunkname = WorldChunks[cx, cy].X + "_" + WorldChunks[cx, cy].Y;
FileStream fileStream = File.Create(Main.ChunkPath + "\\Chunks\\" + chunkname + ".chnk");
StreamWriter writer = new StreamWriter(fileStream);
String json = JsonConvert.SerializeObject(WorldChunks[cx, cy].myTiles, Formatting.None);
writer.Write(json);
writer.Close();
}
Run Code Online (Sandbox Code Playgroud)
加载中:
public void LoadChunk(int xx, int yy)
{
string chunkname = xx + "_" + yy;
if (File.Exists(Main.ChunkPath + "\\Chunks\\" + chunkname + ".chnk"))
{
//If the …Run Code Online (Sandbox Code Playgroud) 我的 Java 程序实现了一个服务器,它应该从客户端通过 websockets 获取一个非常大的文件,使用 gzip 压缩,并且应该检查文件内容中的一些字节模式。
客户端发送嵌入在专有协议中的文件块,因此我从客户端收到一条又一条消息,解析消息并提取 gzipped 文件内容。
我无法在程序内存中保存整个文件,所以我试图解压缩每个块,处理数据并继续下一个块。
我正在使用以下代码:
public static String gzipDecompress(byte[] compressed) throws IOException {
String uncompressed;
try (
ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
GZIPInputStream gis = new GZIPInputStream(bis);
Reader reader = new InputStreamReader(gis);
Writer writer = new StringWriter()
) {
char[] buffer = new char[10240];
for (int length = 0; (length = reader.read(buffer)) > 0; ) {
writer.write(buffer, 0, length);
}
uncompressed = writer.toString();
}
return uncompressed;
}
Run Code Online (Sandbox Code Playgroud)
但是在使用第一个压缩块调用函数时出现以下异常:
java.io.EOFException: Unexpected end of ZLIB …Run Code Online (Sandbox Code Playgroud) 我是使用生成器的新手,已经阅读了一些,但是需要一些帮助来处理大块文本文件。我知道已经讨论了该主题,但是示例代码的解释非常有限,如果不了解正在发生的事情,则很难修改代码。
我的问题很简单,我有一系列大型文本文件,其中包含以下格式的人类基因组测序数据:
chr22 1 0
chr22 2 0
chr22 3 1
chr22 4 1
chr22 5 1
chr22 6 2
Run Code Online (Sandbox Code Playgroud)
文件长度在1Gb到〜20Gb之间,太大而无法读入RAM。所以我想一次读取例如10000行的块/箱中的行,以便我可以在这些箱大小的最后一列上执行计算。
基于此链接,我编写了以下内容:
def read_large_file(file_object):
"""A generator function to read a large file lazily."""
bin_size=5000
start=0
end=start+bin_size
# Read a block from the file: data
while True:
data = file_object.readlines(end)
if not data:
break
start=start+bin_size
end=end+bin_size
yield data
def process_file(path):
try:
# Open a connection to the file
with open(path) as file_handler:
# Create a generator object for the …Run Code Online (Sandbox Code Playgroud) 目前正在使用高级 ui 框架(如版本 2 和 4 的角度)实现我的用户界面代码。
当我想将代码部署到服务器时,我需要通过发出以下命令“ ng build --prod ”来构建项目,因此正在生成许多块文件。
我想知道为什么会生成这些块文件。
我需要以某种方式readstream在nodeJS中克隆a。也就是说,如果我有一个,readStream我需要它的两个副本stream1、stream2。我可以在其中读取流stream1并stream2单独读取。我怎样才能做到这一点,因为据我所知,即使我尝试将原始流传输readStream到stream1,您也无法轻松复制流,stream2我无法单独使用它们中的每一个
我的数据采用以下格式:
TABLE NUMBER 1
FILE: name_1
name_2
TIME name_3
day name_4
-0.01 0
364.99 35368.4
729.99 29307
1094.99 27309.5
1460.99 26058.8
1825.99 25100.4
2190.99 24364
2555.99 23757.1
2921.99 23240.8
3286.99 22785
3651.99 22376.8
4016.99 22006.1
4382.99 21664.7
4747.99 21348.3
5112.99 21052.5
5477.99 20774.1
5843.99 20509.9
6208.99 20259.7
6573.99 20021.3
6938.99 19793.5
7304.99 19576.6
TABLE NUMBER 2
FILE: name_1
name_5
TIME name_6
day name_7
-0.01 0
364.99 43110.4
729.99 37974.1
1094.99 36175.9
1460.99 34957.9
1825.99 34036.3
2190.99 33293.3
2555.99 32665.8
2921.99 …Run Code Online (Sandbox Code Playgroud) chunks ×10
c# ×2
javascript ×2
angular ×1
dataframe ×1
file-io ×1
filestream ×1
generator ×1
gzip ×1
java ×1
large-files ×1
loading ×1
lua ×1
matlab ×1
node-streams ×1
node.js ×1
performance ×1
python ×1
r ×1
reshape ×1
return-value ×1
split ×1
string ×1
text-files ×1
tiles ×1
zlib ×1