深入理解二进制文件(In-depth understanding of binary files)
我正在学习C ++,特别是关于二进制文件结构/操作,因为我对二进制文件,位,咬和十六进制数的主题完全不熟悉,所以我决定向后退一步,对主题建立一个扎实的理解。
在下面我已经包含的图片中,我在
.txt
文件中写了两个单词(blue thief
)。原因是,当我使用hexeditor解码文件时,我想了解信息是如何以十六进制格式存储的。 现在,不要误解我的意思,我并不是试图通过整天阅读十六进制格式来谋生,而只是对二进制文件组合的基本知识有最低限度的理解。 我也知道所有文件都有不同的结构,但只是为了理解,我想知道,“蓝贼”和单个
' '
(空格)这些词是如何被转换成这些字符的。还有一件事是,我听说二进制文件包含三种类型的信息:
header
,ftm
&和data
! 那只关注音频,视频等多媒体文件吗? 因为,除了它看起来只是这个文件中的data
块之外,我似乎看不到任何东西。I am learning C++ specially about binary file structure/manipulation, and since I am totally new to the subject of binary files, bits, bites & hexadecimal numbers, I decided to take one step backward and establish a solid understanding on the subjects.
In the picture I have included below, I wrote two words (
blue thief
) in a.txt
file.The reason for this, is when I decode the file using a hexeditor, I wanted to understand how the information is really stored in hex format. Now, don't get me wrong, I am not trying to make a living out of reading hex formats all day, but only to have a minimum level of understanding the basics of a binary file's composition. I also, know all files have different structures, but just for the sake of understanding, I wanted to know, how exactly the words "blue thief" and a single
' '
(space) were converted into those characters.One more thing, is that, I have heard that binary files contain three types of information:
header
,ftm
& and thedata
! is that only concerned with multimedia files like audios, videos? because, I can't seem to see anything, other than what it looks like a thedata
chunk in this file only.
原文:https://stackoverflow.com/questions/17156522
最满意答案
这就是POSIX要求编写的内容 :
在成功返回常规文件的write()之后:
从该写入修改的文件中的每个字节位置的任何成功read()都将返回该位置的write()指定的数据,直到再次修改这些字节位置。
对文件中相同字节位置的任何后续成功write()都将覆盖该文件数据。
这并不能保证您的数据完全按照该顺序命中磁盘。 只要应用程序“看到”与上述两个语句一致,实现就可以重新排序所需的物理写入。
实际上,内核,甚至磁盘子系统(例如SAN)都可以重新排序写入(通常是出于性能原因)。
因此,您不能依赖写入调用的顺序来保持一致性。 你需要
f[data]sync
。PostgreSQL邮件列表中有趣的电子邮件线程: POSIX文件更新 。 阅读数据库如何处理I / O是了解此类问题的好方法。
(对不起,在这方面不了解Windows。)
This is what POSIX mandates for write:
After a write() to a regular file has successfully returned:
Any successful read() from each byte position in the file that was modified by that write shall return the data specified by the write() for that position until such byte positions are again modified.
Any subsequent successful write() to the same byte position in the file shall overwrite that file data.
This does not provide you with a guarantee that your data will hit the disk in that order at all. The implementation can re-order physical writes all it wants as long is what the applications "see" is consistent with the above two statements.
In practice, the kernel, and even the disk subsystem (think SANs for instance) can re-order writes (for performance reasons usually).
So you can't rely on the order of your write calls for consistency. You'll need
f[data]sync
s.Interesting email thread on the PostgreSQL mailing list: POSIX file updates. Reading on how databases handle I/O is a great way to learn about this type of issue.
(Sorry, don't know about Windows in this respect.)
相关问答
更多-
显然,我可以调用entityManager.flush() 实际上你必须打电话给它。 但是,在这种情况下,数据会在整个事务提交之前保存到数据库中。 这是错误的:数据被同步到数据库,但事务仍未提交,除非您手动提交并控制数据库。 如果您没有在EJB中配置任何内容,并且您的持久性单元是JTA(请参阅带有注释的此问题 ),那么只有在方法从EJB层返回后才会提交事务。 我认为操作顺序与添加到事务中的操作顺序相同。 从我的例子可以看出事实并非如此。 不,JPA规范不强制实现这样做。 这就是为什么有一个flush()操作 ...
-
Java中的文件操作(File Operations in Java)[2022-04-30]
使用java.io.File 列出目录中的所有文件 http://www.javaprogrammingforums.com/java-code-snippets-tutorials/3-how-list-all-files-directory.html File folder = new File(path); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { // Do ... -
csv模块包含写入和读取的方法,这使得这非常简单: import csv with open("test.csv") as file, open("test_tab.csv", "w") as out: reader = csv.reader(file) writer = csv.writer(out, dialect=csv.excel_tab) for row in reader: writer.writerow(row) 不需要自己动手。 请注意我对with ...
-
PHP操作顺序(PHP Order of operations)[2023-05-06]
从里到外。 传递给PHP中的函数的东西称为“表达式”。 将表达式作为参数传递时,实际传递的是该表达式的值。 为此,表达式在传入之前进行求值。 更多关于PHP手册中的表达式。 From the inside out. The things passed into a function in PHP are called "expressions". When you pass an expression as a parameter, what you're really passing is the val ... -
运营顺序(Order of Operations)[2022-07-26]
这根本不是编码问题,这是公式的一个问题。 你需要研究科学记数法 。 0.000683783应为0.00683783(6.83783x10 -3 ) 0.005481717应该是0.05481717(-5.481717x10 -2 ) 等等 见配方 。 It's not a coding problem at all, it's an issue with the formula. You need to study up on scientific notation. 0.000683783 should ... -
这就是POSIX要求编写的内容 : 在成功返回常规文件的write()之后: 从该写入修改的文件中的每个字节位置的任何成功read()都将返回该位置的write()指定的数据,直到再次修改这些字节位置。 对文件中相同字节位置的任何后续成功write()都将覆盖该文件数据。 这并不能保证您的数据完全按照该顺序命中磁盘。 只要应用程序“看到”与上述两个语句一致,实现就可以重新排序所需的物理写入。 实际上,内核,甚至磁盘子系统(例如SAN)都可以重新排序写入(通常是出于性能原因)。 因此,您不能依赖写入调用的顺序 ...
-
给这个镜头: // dependencies const AWS = require('aws-sdk') const unzip = require('unzip') // global process variable is still accessible process.env['PATH'] = process.env['PATH'] + ':' + process.env['/tmp'] // get reference to CodePipeline client const codepip ...
-
是的,第二个代码块等同于第一个代码块。 根据文档 , or比and优先级低。 这意味着if语句被评估为 if ((hand[0] in winning_cards and hand[1] == 'Ace') or (hand[0] == 'Ace' and hand[1] in winning_cards)): 这是你想要的。 您可以返回该布尔表达式的结果来缩短代码: def blackjack_check(hand): winning_cards = [10, 'Jack', 'Que ...
-
我认为没有理由为什么NSManagedObjectContext不会在内部使用GCD,而GCD队列是严格的FIFO。 当然我没有证据证明这一点,但它对我来说非常有意义,因为performBlock的目标是线程安全,并且在给定的上下文中一次只执行一个操作,为什么Apple要从头开始编写系统当一个功能完善的(GCD)已经存在时。 I see no reason why NSManagedObjectContext wouldn't use GCD internally, and GCD queues are s ...
-
在NEURON .MOD文件中,这些部分的操作顺序是什么?(In NEURON .MOD files what is the order of operations of the sections?)[2023-04-09]
对于每个时间步,执行顺序如下: NET_RECEIVE :如果net_send()是一个以此机制为目标的事件,则首先执行此处的行。 否则跳过。 BREAKPOINT中的行:SOLVE ... METHOD行被忽略。 执行SOLVE后的所有行。 使用printf()语句,您将看到两个调用。 但是,其中一个调用实际上并未设置任何状态变量。 它用于计算衍生物。 最后, DERIVATIVE块:计算导数( X' = ... )的值。 请记住,要获得状态变量实际更改的值,请乘以dt 。 For every time- ...