473,398 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

writing binary data whose size exceeds unsinged it

hello, it's me again.
i was implementing a DBMS, as usual, where i needed to call fwrite
using 8-byte integer as the length of the data to be written ( just in
case there is data bigger than 2 GB, which may happen ).
The problem is that fwrite takes a size_t ( an unsiged 4-byte integer
), not 8-byte integer. i also can't play the trick of dividing the
length between the _Size and _Count parameters because their
multiplication is also unsigned int ( in the fwrite implementation ).
My question is, does there exist any IO function that writes data whose
length requires 8-byte integer ?

Jan 27 '06 #1
14 2152
mo**************@gmail.com writes:
hello, it's me again.
i was implementing a DBMS, as usual, where i needed to call fwrite
using 8-byte integer as the length of the data to be written ( just in
case there is data bigger than 2 GB, which may happen ).
The problem is that fwrite takes a size_t ( an unsiged 4-byte integer
), not 8-byte integer. i also can't play the trick of dividing the
length between the _Size and _Count parameters because their
multiplication is also unsigned int ( in the fwrite implementation ).
My question is, does there exist any IO function that writes data whose
length requires 8-byte integer ?


Sure, on systems where size_t is 8 bytes.

If you need to write more data than a single fwrite() call can handle
in your implementation, you should be able to use multiple fwrite()
calls. Assuming you have a 64-bit integer type (e.g., unsigned long
long), you can write a simple wrapper function that invokes fwrite()
as many times as necessary.

<OT>
You might also look for "large file support" in your operating system's
documentation.
</OT>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jan 27 '06 #2

Sure, on systems where size_t is 8 bytes.

If you need to write more data than a single fwrite() call can handle
in your implementation, you should be able to use multiple fwrite()
calls. Assuming you have a 64-bit integer type (e.g., unsigned long
long), you can write a simple wrapper function that invokes fwrite()
as many times as necessary.
Thanks so much, i haven't got the idea until u told me, so i did it :
ulonglong _lfwrite(const void* _Str,size_t _Size,ulonglong _Count,FILE*
_File)
{
union { unsigned int ints[2]; ulonglong count; };

unsigned int loops = ints[1]; // high-order int
unsigned int count_each_loop = ints[0];

ulonglong items_written = 0;

while(loops)
{
loops--;
items_written += fwrite(_Str,_Size,count_each_loop,_File);
}

return items_written;
}

<OT>
You might also look for "large file support" in your operating system's
documentation.
</OT>


My operating system is windows XP, i think the large file support is
about the file system. FAT32 can't support files larger than 4 GB. but
NTFS can support up to 256 TB in a clustered system, and up to 2 TB
otherwise. source
http://www.windowsitpro.com/Articles...rticleID=27253

Jan 27 '06 #3

<mo**************@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
hello, it's me again.
i was implementing a DBMS, as usual, where i needed to call fwrite
using 8-byte integer as the length of the data to be written ( just in
case there is data bigger than 2 GB, which may happen ).
The problem is that fwrite takes a size_t ( an unsiged 4-byte integer
), not 8-byte integer.
The range of 'size_t' is implementation-dependent (subject
to minimum requirements)
i also can't play the trick of dividing the
length between the _Size and _Count parameters because their
multiplication is also unsigned int ( in the fwrite implementation ).
Yes, but note that you can call 'fwrite()' as many times
as you like. :-)
My question is, does there exist any IO function that writes data whose
length requires 8-byte integer ?


There might. But the language doesn't require 'size_t'
to have size of eight bytes.
for(i = 0; i < chunks; ++i)
fwrite( /* etc */ );

-Mike

Jan 27 '06 #4
mo**************@gmail.com writes:
Sure, on systems where size_t is 8 bytes.

If you need to write more data than a single fwrite() call can handle
in your implementation, you should be able to use multiple fwrite()
calls. Assuming you have a 64-bit integer type (e.g., unsigned long
long), you can write a simple wrapper function that invokes fwrite()
as many times as necessary.
Please don't snip attribution lines (the line that says
"So-and-so writes:").
Thanks so much, i haven't got the idea until u told me, so i did it :
Please don't use silly abbreviations like "u" for "you". If you want
us to read what you write, take the time to spell things out.
ulonglong _lfwrite(const void* _Str,size_t _Size,ulonglong _Count,FILE*
_File)
{
union { unsigned int ints[2]; ulonglong count; };

unsigned int loops = ints[1]; // high-order int
unsigned int count_each_loop = ints[0];

ulonglong items_written = 0;

while(loops)
{
loops--;
items_written += fwrite(_Str,_Size,count_each_loop,_File);
}

return items_written;
}


Don't use identifiers starting with underscores. Many of them are
reserved for use by the implementation.

What is "ulonglong"? It looks like it should be an alias for
"unsigned long long", but why use an alias? It can only cause
confusion.
<OT>
You might also look for "large file support" in your operating system's
documentation.
</OT>


My operating system is windows XP, i think the large file support is
about the file system. FAT32 can't support files larger than 4 GB. but
NTFS can support up to 256 TB in a clustered system, and up to 2 TB
otherwise. source
http://www.windowsitpro.com/Articles...rticleID=27253


The "OT" tags are short for off-topic, i.e., the issue isn't relevant
to this newsgroup. (Yeah, I know, it's another silly abbreviation.)
Details of Windows XP are definitely off-topic here; there are plenty
of Windows newsgroups.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jan 28 '06 #5
On Sat, 28 Jan 2006 00:13:13 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.org> wrote:

What is "ulonglong"?
its a river in east africa
It can only cause confusion.


only if you paddle backwards.

gd&r
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jan 28 '06 #6

Keith Thompson wrote:
Please don't snip attribution lines (the line that says
"So-and-so writes:").
<OT>
You might also look for "large file support" in your operating system's
documentation.
</OT>


My operating system is windows XP, i think the large file support is
about the file system. FAT32 can't support files larger than 4 GB. but
NTFS can support up to 256 TB in a clustered system, and up to 2 TB
otherwise. source
http://www.windowsitpro.com/Articles...rticleID=27253


The "OT" tags are short for off-topic, i.e., the issue isn't relevant
to this newsgroup. (Yeah, I know, it's another silly abbreviation.)
Details of Windows XP are definitely off-topic here; there are plenty
of Windows newsgroups.


Sorry for that. I am totally new to posting to news groups; this is my
second post so I don't really know the system around here.
ulonglong _lfwrite(const void* _Str,size_t _Size,ulonglong _Count,FILE*
_File)
Don't use identifiers starting with underscores. Many of them are
reserved for use by the implementation.


I'll follow the advice, thank you.

What is "ulonglong"? It looks like it should be an alias for
"unsigned long long", but why use an alias? It can only cause
confusion.

I used the alias because I use this type a lot in my code and I surely
don't want to forget the "unsigned" before it undeliberately. So I made
the alias for this reason. Also the alias gives an easy way to change
the type - for example: to signed - in all the code, by just one
change.
Thanks so much, i haven't got the idea until u told me, so i did it :


Please don't use silly abbreviations like "u" for "you". If you want
us to read what you write, take the time to spell things out.


Sorry for that too .. It was unintentional. It just came from being
used to use it in instant messaging. Even when I write big essays, and
intend to write "you" correctly; I sometimes miss and type it "u"
subconciously a few times. (Note: my first language is not english).
Thanks for bearing my 'mistakes' so far, and hope you will forgive me
:). [ I hope smilies are allowed too ].

Jan 28 '06 #7
mo**************@gmail.com wrote:
What is "ulonglong"? It looks like it should be an alias for
"unsigned long long", but why use an alias? It can only cause
confusion.

I used the alias because I use this type a lot in my code and I surely
don't want to forget the "unsigned" before it undeliberately. So I made
the alias for this reason. Also the alias gives an easy way to change
the type - for example: to signed - in all the code, by just one
change.

Does your compiler/platform have the C99 size types? If so, you can use
uint64_t and friends.

--
Ian Collins.
Jan 28 '06 #8

Ian Collins wrote:
mo**************@gmail.com wrote:
What is "ulonglong"? It looks like it should be an alias for
"unsigned long long", but why use an alias? It can only cause
confusion.

I used the alias because I use this type a lot in my code and I surely
don't want to forget the "unsigned" before it undeliberately. So I made
the alias for this reason. Also the alias gives an easy way to change
the type - for example: to signed - in all the code, by just one
change.

Does your compiler/platform have the C99 size types? If so, you can use
uint64_t and friends.

I don't think so. My compiler is Visual Studio 2005 in Windows XP. Does
anybody have an idea where I can find the list of compilers supporting
C99 standard ? I've been searching for a while and i didn't find any.

Jan 28 '06 #9
mo**************@gmail.com wrote:
Ian Collins wrote:
mo**************@gmail.com wrote:
What is "ulonglong"? It looks like it should be an alias for
"unsigned long long", but why use an alias? It can only cause
confusion.

I used the alias because I use this type a lot in my code and I surely
don't want to forget the "unsigned" before it undeliberately. So I made
the alias for this reason. Also the alias gives an easy way to change
the type - for example: to signed - in all the code, by just one
change.


Does your compiler/platform have the C99 size types? If so, you can use
uint64_t and friends.


I don't think so. My compiler is Visual Studio 2005 in Windows XP. Does
anybody have an idea where I can find the list of compilers supporting
C99 standard ? I've been searching for a while and i didn't find any.

Just see if you have inttypes.h, they are declared in there. Nothing
special, just typedefs.

--
Ian Collins.
Jan 28 '06 #10
mo**************@gmail.com writes:
Keith Thompson wrote:

[snip]
What is "ulonglong"? It looks like it should be an alias for
"unsigned long long", but why use an alias? It can only cause
confusion.


I used the alias because I use this type a lot in my code and I surely
don't want to forget the "unsigned" before it undeliberately. So I made
the alias for this reason. Also the alias gives an easy way to change
the type - for example: to signed - in all the code, by just one
change.


A better solution is just to remember to type "unsigned long long"
each time. Or decide exactly why you're using that particular type,
and create an alias based on that reason. If you specifically want to
use unsigned long long, just use unsigned long long. If you want a
large index type that might be either unsigned long long or unsigned
long, declare a typedef such as "large_index".

The name "ulonglong" clearly implies "unsigned long long". Imagine
the confusion if you change it to

typedef long long ulonglong;

Creating typedefs for predefined types is ok if the typedef specified
the purpose for which you're using the type. Typedefs that just save
a few keystrokes are a waste of time. You're likely to read your code
many more times than you write it; a little extra effort while you're
writing it really pays off. (This applies both to C and to English.)
> > Thanks so much, i haven't got the idea until u told me, so i did it :


Please don't use silly abbreviations like "u" for "you". If you want
us to read what you write, take the time to spell things out.


Sorry for that too .. It was unintentional. It just came from being
used to use it in instant messaging. Even when I write big essays, and
intend to write "you" correctly; I sometimes miss and type it "u"
subconciously a few times. (Note: my first language is not english).
Thanks for bearing my 'mistakes' so far, and hope you will forgive me
:). [ I hope smilies are allowed too ].


Yes, smilies are allowed. 8-)} And your efforts are greatly
appreciated.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jan 28 '06 #11
mo**************@gmail.com writes:
Ian Collins wrote:
mo**************@gmail.com wrote:
>
>>What is "ulonglong"? It looks like it should be an alias for
>>"unsigned long long", but why use an alias? It can only cause
>>confusion.
>>
>
>
> I used the alias because I use this type a lot in my code and I surely
> don't want to forget the "unsigned" before it undeliberately. So I made
> the alias for this reason. Also the alias gives an easy way to change
> the type - for example: to signed - in all the code, by just one
> change.
>

Does your compiler/platform have the C99 size types? If so, you can use
uint64_t and friends.

I don't think so. My compiler is Visual Studio 2005 in Windows XP. Does
anybody have an idea where I can find the list of compilers supporting
C99 standard ? I've been searching for a while and i didn't find any.


I don't know about Visual Studio, but a lot of compilers support
<inttypes.h> and/or type long long (both new features in C99) that
don't necessarily have full C99 support.

There's also a version of <inttypes.h> that can be used with C90
compilers at <http://www.lysator.liu.se/c/q8/index.html>.

Note that any code that depends on 64-bit types integer types, or on
long long, isn't going to be entirely portable until C99 actually
catches on -- but it's not necessarily going to be limited to full C99
implementations.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jan 28 '06 #12
Mark McIntyre wrote:
Keith Thompson <ks***@mib.org> wrote:
What is "ulonglong"?


its a river in east africa


Isn't that the one that Katherine Hepburn descended with Humphrey
Bogart, circa 1914?

--
"The power of the Executive to cast a man into prison without
formulating any charge known to the law, and particularly to
deny him the judgement of his peers, is in the highest degree
odious and is the foundation of all totalitarian government
whether Nazi or Communist." -- W. Churchill, Nov 21, 1943
Jan 28 '06 #13
mo**************@gmail.com wrote:
Keith Thompson wrote:

.... snip ...

Please don't use silly abbreviations like "u" for "you". If you
want us to read what you write, take the time to spell things out.


Sorry for that too .. It was unintentional. It just came from being
used to use it in instant messaging. Even when I write big essays,
and intend to write "you" correctly; I sometimes miss and type it
"u" subconciously a few times. (Note: my first language is not
english). Thanks for bearing my 'mistakes' so far, and hope you
will forgive me :). [ I hope smilies are allowed too ].


They are. You are doing fine, and learning at a great rate. It's
the ones who refuse to listen and generally clutter the newsgroups
that annoy. The following references may be useful.

http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.greenend.org.uk/rjk/2000/06/14/quoting.html
http://www.i-hate-computers.demon.co.uk/
http://web.ukonline.co.uk/g.mccaugha...ks/uquote.html

--
"The power of the Executive to cast a man into prison without
formulating any charge known to the law, and particularly to
deny him the judgement of his peers, is in the highest degree
odious and is the foundation of all totalitarian government
whether Nazi or Communist." -- W. Churchill, Nov 21, 1943
Jan 28 '06 #14
On Fri, 27 Jan 2006 21:38:00 -0500, in comp.lang.c , CBFalconer
<cb********@yahoo.com> wrote:
Mark McIntyre wrote:
Keith Thompson <ks***@mib.org> wrote:
What is "ulonglong"?


its a river in east africa


Isn't that the one that Katherine Hepburn descended with Humphrey
Bogart, circa 1914?


we /both/ need to get out more.
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jan 28 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Navin | last post by:
Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. hi, guys i have asp application running on iis 5.0 windows 2000 i use...
6
by: Sebastian Kemi | last post by:
How should a write a class to a file? Would this example work: object *myobject = 0; tfile.write(reinterpret_cast<char *>(myobject), sizeof(*object)); / sebek
5
by: rob | last post by:
hey every1, I've got alot of data to write out to file and it's all just 1's and 0's. It's all stored in 2 dimensional arrays of width 32 and varying height. At the moment it's all just...
6
by: DanielEKFA | last post by:
Hey there :) I was once told that the STL classes had member functions to write their data to disk and to restore that data. Searching google (and why are there no "stl" or "map" manpages?), it...
2
by: Jason Heyes | last post by:
I want to read the binary contents of a file whose size is over 1 megabyte. I tried to use this function. bool read_file(const char *fname, std::vector<char> &data) { std::ifstream in(fname);...
2
by: phyzics | last post by:
I am porting an application from C++ to C#, and am having trouble finding a way to quickly and efficiently write structures to a binary file. In C++ this is trivial because all that is necessary is...
2
by: scallst | last post by:
Hi! I'm new in PHP and I have a problem on sending a socket message to c-server. I am able to connect using socket_connect but my problem is I have to setup TCP message in a special format as my...
4
by: ycliuwz | last post by:
Hi, Could anyone help me out on this. I'm trying to store an unsinged int that will at most use 1byte into a binary file but to no avail. could anyone help me out on this? thanks in advance
3
by: Willy Stevens | last post by:
Hello, In my application I have to read sometimes quite big chunk of binary data. I have a buffer which default size is 32000 bytes. But how could I read binary data that exceeds 32000 bytes?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.