Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 03-17-09   #1 (permalink)
New to Overclock.net
 
adramalech707's Avatar
 
intel nvidia

Join Date: Feb 2008
Posts: 219

Rep: 5 adramalech707 Unknown
Unique Rep: 5
Folding Team Rank: 708
Trader Rating: 0
Default writing custom data type

okay so i was wondering about some how figuring out how to allocate a really large amount of storage for a variable....like i want to be able to find really big Fibonacci numbers...etc...

i wanted to make a 128bit allocation(an extended double)....like extend the data type header file....
__________________
x2 4600+ @2.6ghz

x2 6400+ @ 3.5ghz

Quote:
When you say "I wrote a program that crashed Windows", people just stare at you blankly and say "Hey, I got those with the system, *for free*"
-Linus Torvalds
Quote:
"How should I know if it works? That's what beta testers are for. I only coded it."
-Linus Torvalds
Quote:
Be warned that typing \fBkillall \fIname\fP may not have the desired effect on non-Linux systems, especially when done by a privileged user.
-killall man page

System: Intel build
CPU
i7 860 @ 2.8ghz
Motherboard
gigabyte p55-ud6
Memory
dominator gt CMG4GX3M2A1600C7
Graphics Card
bfg 9600gt oc2
Hard Drive
wd caviar 500gb
Power Supply
750watt toughpower
Case
antec 900
CPU cooling
coolermaster hyper tx3
GPU cooling
stock
OS
windows 7/ gentoo 64bit
Monitor
samsung 2243swx
adramalech707 is offline I fold for Overclock.net   Reply With Quote
Old 03-17-09   #2 (permalink)
2 + 2 = 5
 
DuckieHo's Avatar
 
intel nvidia

Join Date: Nov 2006
Location: In a Chair.
Posts: 34,851

Rep: 4164 DuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guruDuckieHo is a guru
Unique Rep: 1903
Trader Rating: 56
Default

Language?
__________________
To answer most of your questions: (1) a fridge cannot cool a PC (2) 64-bit OS for over 3.4GB (3) If a PCIe card fits, it should work (4) Resolution, not screen size (5) If you have a question, it is not news (6) Report, not respond to Spam (7) Single-Rail/Non-Modular PSUs are not always better than Multi-Rail/Modular


System: Three Dead Mobos in a Year
CPU
Q6600 (3.4GHz)
Motherboard
EVGA 780i
Memory
2x2GB OCZ Reaper 1096MHz
Graphics Card
GTX260 55nm
Hard Drive
PERC 6/i: 3xRAID0 7200.12 500GB
Sound Card
X-Fi XtremeMusic
Power Supply
Corsair 620HX
Case
Li Lian PC-V2100 [10x120mm fans]
CPU cooling
FuZion V2 + Quad-Heatercore
GPU cooling
EK Block + DDC-3.2
OS
Vista Ultimate 64
Monitor
Samsung 226BW "C" + Sceptre 19"
DuckieHo is offline Overclocked Account DuckieHo's Gallery   Reply With Quote
Old 03-17-09   #3 (permalink)
New to Overclock.net
 
adramalech707's Avatar
 
intel nvidia

Join Date: Feb 2008
Posts: 219

Rep: 5 adramalech707 Unknown
Unique Rep: 5
Folding Team Rank: 708
Trader Rating: 0
Default

i am sorry in C and java
__________________
x2 4600+ @2.6ghz

x2 6400+ @ 3.5ghz

Quote:
When you say "I wrote a program that crashed Windows", people just stare at you blankly and say "Hey, I got those with the system, *for free*"
-Linus Torvalds
Quote:
"How should I know if it works? That's what beta testers are for. I only coded it."
-Linus Torvalds
Quote:
Be warned that typing \fBkillall \fIname\fP may not have the desired effect on non-Linux systems, especially when done by a privileged user.
-killall man page

System: Intel build
CPU
i7 860 @ 2.8ghz
Motherboard
gigabyte p55-ud6
Memory
dominator gt CMG4GX3M2A1600C7
Graphics Card
bfg 9600gt oc2
Hard Drive
wd caviar 500gb
Power Supply
750watt toughpower
Case
antec 900
CPU cooling
coolermaster hyper tx3
GPU cooling
stock
OS
windows 7/ gentoo 64bit
Monitor
samsung 2243swx
adramalech707 is offline I fold for Overclock.net   Reply With Quote
Old 03-17-09   #4 (permalink)
With great difficulty
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 5,210

Rep: 614 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 370
FAQs Submitted: 6
Trader Rating: 5
Default

malloc lets you allocate arbitrary amounts of memory in C. You could also create a suitably sized struct

In java, just make a class that does what you need. For large numbers, look at the BigInteger class
__________________
System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is offline Overclocked Account   Reply With Quote
Old 03-17-09   #5 (permalink)
New to Overclock.net
 
adramalech707's Avatar
 
intel nvidia

Join Date: Feb 2008
Posts: 219

Rep: 5 adramalech707 Unknown
Unique Rep: 5
Folding Team Rank: 708
Trader Rating: 0
Default

thanks....i thought it would be something like malloc....

so i would just do

Code:
#include <stdlib.h>
#define MAX_SIZE 1000

static void main(){
    static int array[MAX_SIZE];
    int i = 2;
    array[0] = 1;
    array[1] = 1;
    fib = malloc(......); <---whatever the size i wish to make fib....
    fib = array[i-1] + array[i-2];
    array[i] = fib;
}
__________________
x2 4600+ @2.6ghz

x2 6400+ @ 3.5ghz

Quote:
When you say "I wrote a program that crashed Windows", people just stare at you blankly and say "Hey, I got those with the system, *for free*"
-Linus Torvalds
Quote:
"How should I know if it works? That's what beta testers are for. I only coded it."
-Linus Torvalds
Quote:
Be warned that typing \fBkillall \fIname\fP may not have the desired effect on non-Linux systems, especially when done by a privileged user.
-killall man page

System: Intel build
CPU
i7 860 @ 2.8ghz
Motherboard
gigabyte p55-ud6
Memory
dominator gt CMG4GX3M2A1600C7
Graphics Card
bfg 9600gt oc2
Hard Drive
wd caviar 500gb
Power Supply
750watt toughpower
Case
antec 900
CPU cooling
coolermaster hyper tx3
GPU cooling
stock
OS
windows 7/ gentoo 64bit
Monitor
samsung 2243swx
adramalech707 is offline I fold for Overclock.net   Reply With Quote
Old 03-17-09   #6 (permalink)
With great difficulty
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 5,210

Rep: 614 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 370
FAQs Submitted: 6
Trader Rating: 5
Default

Quote:
Originally Posted by adramalech707 View Post
thanks....i thought it would be something like malloc....

so i would just do

Code:
#include <stdlib.h>
#define MAX_SIZE 1000

static void main(){
    static int array[MAX_SIZE];
    int i = 2;
    array[0] = 1;
    array[1] = 1;
    fib = malloc(......); <---whatever the size i wish to make fib....
    fib = array[i-1] + array[i-2];
    array[i] = fib;
}
What type is fib in that code snippet? If it's an int there's no reason to malloc it. If it isn't it's doubtful that you will be able to assign an int (the result of array[i-1] + array[i-2]) directly into it. If you're creating your own datatype you need to create your own functions to manipulate it.
__________________
System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is offline Overclocked Account   Reply With Quote
Old 03-19-09   #7 (permalink)
New to Overclock.net
 
adramalech707's Avatar
 
intel nvidia

Join Date: Feb 2008
Posts: 219

Rep: 5 adramalech707 Unknown
Unique Rep: 5
Folding Team Rank: 708
Trader Rating: 0
Default

okay soo i was kindof not thinking when i wrote that little code...i think what i wanted was this....i hope this kindof half way looks like it should work...

type_def struct{
long double* num = malloc(2^128);////<---want to allocate 128bits
}fib_array;

static int main(){
static int i = 2;
fib_array array[MAX_SIZE];
fib_array fib;
array[0].num = 1;
array[1].num = 1;

while(i != MAX_SIZE){
fib.num = array[i-1].num + array[i-2].num;
array = fib.num;
i++;
}
for(i=0; i < MAX_SIZE; i++){
printf("%fib_num", array[i]); ///<---i don't think i formatted this correctly
}
}
__________________
x2 4600+ @2.6ghz

x2 6400+ @ 3.5ghz

Quote:
When you say "I wrote a program that crashed Windows", people just stare at you blankly and say "Hey, I got those with the system, *for free*"
-Linus Torvalds
Quote:
"How should I know if it works? That's what beta testers are for. I only coded it."
-Linus Torvalds
Quote:
Be warned that typing \fBkillall \fIname\fP may not have the desired effect on non-Linux systems, especially when done by a privileged user.
-killall man page

System: Intel build
CPU
i7 860 @ 2.8ghz
Motherboard
gigabyte p55-ud6
Memory
dominator gt CMG4GX3M2A1600C7
Graphics Card
bfg 9600gt oc2
Hard Drive
wd caviar 500gb
Power Supply
750watt toughpower
Case
antec 900
CPU cooling
coolermaster hyper tx3
GPU cooling
stock
OS
windows 7/ gentoo 64bit
Monitor
samsung 2243swx
adramalech707 is offline I fold for Overclock.net   Reply With Quote
Old 03-19-09   #8 (permalink)
With great difficulty
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 5,210

Rep: 614 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 370
FAQs Submitted: 6
Trader Rating: 5
Default

Quote:
Originally Posted by adramalech707 View Post
okay soo i was kindof not thinking when i wrote that little code...i think what i wanted was this....i hope this kindof half way looks like it should work...

type_def struct{
long double* num = malloc(2^128);////<---want to allocate 128bits
}fib_array;
A few things here. Firstly, malloc takes the number of bytes you want to allocate, not the number of bits. To allocate 128 bits malloc(16) is what you would want. Also, the '^' operator in C performs XOR, it does act as an exponent. And I'm not sure, but I seriously doubt that you can put code in a struct definition. Also, here's no reason to allocate stack space on the heap for a single variable. If you want a struct that has a long double as a field, use

Code:
typedef struc{
long double num;
}fib_array;
But if a struct has only one field, there's no reason to use a struct. Just use a long double instead of a struct with a long double in it

Quote:
static int main(){
static int i = 2;
fib_array array[MAX_SIZE];
fib_array fib;
array[0].num = 1;
array[1].num = 1;

while(i != MAX_SIZE){
fib.num = array[i-1].num + array[i-2].num;
array = fib.num;
i++;
}
for(i=0; i < MAX_SIZE; i++){
printf("%fib_num", array[i]); ///<---i don't think i formatted this correctly
}
}
You probably want array[i] instead of array in the highlighted line. Also, it's doesn't make any difference, but when you're iterating through an array it's better style to use a for loop than a while loop

One last point. If you're working with the fibonacci sequence you're working entirely with integers, so you should use a long instead of a double. double's are not precise, so once you get beyond a certain range it no longer stores all the digits in the number
__________________
System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw

Last edited by rabidgnome229 : 03-19-09 at 03:12 PM
rabidgnome229 is offline Overclocked Account   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 08:02 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.16917 seconds with 8 queries