Thread: How many chars does it take to fill up 1 megabyte?

  1. #16
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    GOT IT
    Code:
    In new post
    Last edited by bikr692002; 04-05-2006 at 06:04 PM.

  2. #17
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by ChaosEngine
    You're confusing pointer size with byte size (that's actually an over-simplification, but it'll do for now).
    Perhaps you are not familiar with the C and C++ definition of byte. This may explain it better than me.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #18
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Ugh, is there any other way to make the Secure Disk Cleanse loop faster?
    Code:
    #include <stdio.h>
    #include <fstream>
    #include <iostream>
    #include <windows.h>
    int main()
    {
        long end,Oend,begin,Obegin;
    	std::string Dir,File,Option;
    	int Loop,SizeOfDisk,SizeOfFile,OrigSizeOfFile;
    	Loop=1;
    	std::cout<<"Welcome to C.J.'s Security 'suite'!\n";
    	std::cout<<"Please enter what you want to do.\n";
    	std::cout<<"To select Secure Disk Wipe, input SDW.\n";
    	std::cout<<"To select Secure Disk Cleanse, input SDC.\n";
    	std::cout<<"To select Secure File Deletion, input SFD.\n";
    	std::cout<<"To select ---this option is not yet available---.\n";
    	std::cout<<"To select ---this option is not yet available---.\n";
    	std::cout<<"Option:";
    	getline(std::cin,Option,'\n');
    	if(Option=="SDW")
    	{
    		std::cout<<"Sorry,This option is not yet available";
    		std::cin.get();
    	}
    	if(Option=="SDC")
    	{
    		std::cout<<"Please enter Disk(Ex. C:\\):";
    		getline(std::cin,Dir,'\n');
    		if(Dir.length()!=3)
    		{
    			while(Loop==1)
    			{
    				File="";
    				std::cout<<"\nPlease enter Disk:";
    				getline(std::cin,Dir,'\n');
    				if(Dir.length()==3)
    				{
    					Loop=0;
    				}
    			}
    			Loop=1;
    		}
    		File=Dir;
    		File="SecureDiskCleanse.txt";
    		std::ofstream a_file(File.c_str());
    		while(Loop==1)
    		{
    			typedef BOOL (WINAPI *PGETDISKFREESPACEEX)(LPCSTR,
    			PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
    			PGETDISKFREESPACEEX pGetDiskFreeSpaceEx;
    			__int64 i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes;
    			pGetDiskFreeSpaceEx=(PGETDISKFREESPACEEX)GetProcAddress(
    			GetModuleHandle("kernel32.dll"),
    							"GetFreeDiskSpaceExA");
    			GetDiskFreeSpaceExA(
    								Dir.c_str(),
    								NULL,
    								NULL,
    								(PULARGE_INTEGER)&i64FreeBytes);
    			a_file<<"Secure Disk Cleanse.";
    			SizeOfDisk=i64FreeBytes/1024/1024;
    			if(SizeOfDisk<100)
    			{
    				Loop=0;
    			}
    		}
    		a_file.close();
    		File="DEL "+File;
    		system(File.c_str());
    		std::cin.get();
    	}
    	if(Option=="SFD")
    	{
    		std::cout<<"Please enter file path and name.:";
    		getline(std::cin,File,'\n');
    		std::ifstream OrigSize_file(File);
    		Obegin=OrigSize_file.tellg();
    		OrigSize_file.seekg(0,std::ios::end);
    		Oend=OrigSize_file.tellg();
    		OrigSize_file.close();
    		OrigSizeOfFile=(Oend-Obegin);
    		std::ofstream a_file(File.c_str(), std::ios::trunc);
    		while(Loop==1)
    		{
    		    std::ifstream Size_File(File);
    		    begin=Size_File.tellg();
    		    Size_File.seekg(0,std::ios::end);
    		    end=Size_File.tellg();
    		    Size_File.close();
    		    SizeOfFile=(end-begin);
    			a_file<<"Secure File Deletion.";
    			if(SizeOfFile>(OrigSizeOfFile+10))
    			{
    				Loop=0;
    			}
    		}
    		a_file.close();
    		File="DEL "+File;
    		system(File.c_str());
    		std::cin.get();
    	}
    	else
    	{
    		std::cin.get();
    	}
    	return 0;
    }

  4. #19
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by Dave_Sinkula
    Perhaps you are not familiar with the C and C++ definition of byte. This may explain it better than me.
    Are you referring to me or Ancient Dragon?
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  5. #20
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by ChaosEngine
    Are you referring to me or Ancient Dragon?
    Possibly both.
    It is possible for a "32-bit system" to have a char that is 32 bits. It is possible for a "32-bit system" to have a char of 8 bits.
    It is possible for a "64-bit system" to have a pointer that is 64 bits. It is possible for a "64-bit system" to have a pointer with 32 bits.
    It is possible for a "64-bit system" to have an int that is 64 bits. It is possible for a "64-bit system" to have an int with 32 bits.

    I am beginning to much prefer the ILP32, ILP32LL, etc. conventions for descriptions -- although it still doesn't fill all the gaps.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #21
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by Dave_Sinkula
    Possibly both.
    It is possible for a "32-bit system" to have a char that is 32 bits. It is possible for a "32-bit system" to have a char of 8 bits.
    It is possible for a "64-bit system" to have a pointer that is 64 bits. It is possible for a "64-bit system" to have a pointer with 32 bits.
    It is possible for a "64-bit system" to have an int that is 64 bits. It is possible for a "64-bit system" to have an int with 32 bits.

    I am beginning to much prefer the ILP32, ILP32LL, etc. conventions for descriptions -- although it still doesn't fill all the gaps.
    I am aware of the ILP notation. As I said previously, my original post was an oversimplification. A "64-bit system" refers to the width of the address bus and has nothing to do with the char size. Of course it is possible for a 32, 64 or 128 bit system to have their char type as those sizes, but it's very rare in practice, and what I was trying to correct was Ancient Dragons implication that a 64bit system will always have a 64bit char type.

    I believe on win64 it uses IL32P64. As far as I can see, however a char is still 8 bits.
    Last edited by ChaosEngine; 04-06-2006 at 04:17 PM.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  7. #22
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Quote Originally Posted by bikr692002
    How many chars(i.e. A) does it take to fill up 1 megabyte?
    Only 1 if you re-use it :-)

  8. #23
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    >>trying to correct was Ancient Dragons implication that a 64bit system will always have a 64bit char type.


    After re-reading my post -- I see it is technically incorrect as you mentioned. The point was that there is no standard number of bits in 1 byte. sizeof(char) will always be 1 regardless of the number of bits.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question On how to Fill icmp_data
    By Antigloss in forum Linux Programming
    Replies: 3
    Last Post: 04-25-2007, 09:42 PM
  2. Replies: 3
    Last Post: 12-22-2004, 07:29 PM
  3. Counting how many chars in a string
    By tigs in forum C Programming
    Replies: 4
    Last Post: 08-05-2002, 12:25 AM
  4. really got stuck with unsigned chars
    By Abdi in forum C Programming
    Replies: 7
    Last Post: 06-11-2002, 12:47 PM
  5. fancy strcpy
    By heat511 in forum C++ Programming
    Replies: 34
    Last Post: 05-01-2002, 04:29 PM