深入理解二进制文件(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操作顺序(EntityManager operations order)
Java中的文件操作(File Operations in Java)
麻烦的Python操作/循环顺序(Trouble with Python order of operations/loop)
PHP操作顺序(PHP Order of operations)
运营顺序(Order of Operations)
保证文件操作的顺序(Guarantees of order of the operations on file)
NodeJS Lambda问题与操作顺序(NodeJS Lambda issue with order of operations)
“和”和“或”的操作顺序是什么?(What is the order of operations for 'and' and 'or'?)
NSManagedObjectContext的performBlock方法是否保证了操作的顺序?(Does NSManagedObjectContext's performBlock method guarantee the order of operations?)
在NEURON .MOD文件中,这些部分的操作顺序是什么?(In NEURON .MOD files what is the order of operations of the sections?)
相关文章
更多elasticsearch too many open files
Hadoop Java程序-files功能测试
flume写入Hadoop hdfs报错 Too many open files
深入理解Android:卷2.pdf电子书下载
HttpClient 上传文件
Hadoop HDFS 文件与分块理解
深入理解Magento -前言
Storm Topology的并发度
memcached全面剖析–3.memcached的删除机制和发展方向
深入理解Hadoop集群和网络 PDF
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!