Sponsored Content
Full Discussion: fgets problems
Top Forums Programming fgets problems Post 302397047 by CRGreathouse on Saturday 20th of February 2010 02:29:33 PM
Old 02-20-2010
Quote:
Originally Posted by Corona688
Memory is memory. It doesn't have to track the contents of the pari block to notice clobbering happening outside it.
Sure -- but that's not the problem (and it won't be the problem). Every time the library uses the stack it ensures that there's room for what it's creating. Also, the stack is very large -- at least 20 MB and sometimes as big as 1 GB, with its pointer avma moving by [only] several bytes per call.

The real problem with memory management is leaving garbage on the stack (another possibility is returning corrupted objects). The usual technique for is

Code:
GEN genericfunction(----) {
	pari_sp ltop = avma;	// Keep a pointer to the top of the stack's current location
	GEN r;	// Return value (assigned below)

	// ...
	
	r = gerepileupto(ltop, r);	// copy r to the top of the stack and move avma just above it
	return r;
}

which ensures that you're not leaving garbage on the stack. But this is somewhat more complicated by returning complicated objects like vectors. For example:
Code:
GEN vector = cgetg(4, t_VEC); // Make a vector
gel(vector, 1) = gen_2;
int i = 2;
for(; i < 4; i++)
  gel(vector, i) = addii(gel(vector, i-1), mulii(gel(vector, i-1), gel(vector, i-1))); // v[i] = v[i-1] + v[i-1]^2

Memory diagram:

(vector with pointers to its members A, B, and C)(A)(garbage)(B)(garbage)(C)
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

'make' problems (compliation problems?)

I'm trying to compile and install both most recent version of 'make' and the most recent version of 'openssh' on my Sparc20. I've run into the following problems... and I don't know what they mean. Can someone please help me resolve these issues? I'm using the 'make' version that was... (5 Replies)
Discussion started by: xyyz
5 Replies

2. UNIX for Dummies Questions & Answers

Problems with ld.so.1

I renamed ld.so.1 on a Sun machine running Solaris 2.6. Now I cannot boot the system and I can use only very few commands in Maintenance Mode. Can someone help me? (3 Replies)
Discussion started by: ciccio
3 Replies

3. Programming

fgets()

does anyone knows how to accept a command from a user.. i was wondering to use fgets(), but got no idea how to start it... (4 Replies)
Discussion started by: skanky
4 Replies

4. Programming

Problem with fgets and rewind function ..

Hello Friends, I got stuck with fgets () & rewind() function .. Please need help.. Actually I am doing a like, The function should read lines from a txt file until the function is called.. If the data from the txt file ends then it goes to the top and then again when the function is called... (1 Reply)
Discussion started by: user_prady
1 Replies

5. Programming

Question about NULL Character & fgets()

Assume client send the message " Hello ", i get output such as Sent mesg: hello Bytes Sent to Client: 6 bytes_received = recv(clientSockD, data, MAX_DATA, 0); if(bytes_received) { send(clientSockD, data, bytes_received, 0); data = '\0';... (2 Replies)
Discussion started by: f.ben.isaac
2 Replies

6. Programming

[C] fgets problem with SIGINT singlal!!!

Hi all, I have this method to read a string from a STDIN: void readLine(char* inputBuffer){ fgets (inputBuffer, MAX_LINE, stdin); fflush(stdin); /* remove '\n' char from string */ if(strlen(inputBuffer) != 0) inputBuffer = '\0'; } All work fine but if i... (1 Reply)
Discussion started by: hurricane86
1 Replies

7. UNIX for Dummies Questions & Answers

Problems with using less

Hello, I am having problems with using less on Linux version 2.6.18-92.1.17.el5 (brewbuilder@hs20-bc1-7.build.redhat.com) (gcc version 4.1.2 20071124 (Red Hat 4.1.2-42)). I am using csh but have the same problems on bash. If I pipe something to less it works perfectly i.e. cat file | less... (9 Replies)
Discussion started by: z1dane
9 Replies

8. Programming

fgets problems newline

hello, i'm trying to write a C-program that reads a file line by line. (and searches each line for a given string) This file is an special ASCII-database-file, with a lot of entries. I checked the line with most length, and it was about 4000 characters. With google i found several... (4 Replies)
Discussion started by: p1cm1n
4 Replies

9. Programming

fgets read file line with "\n" inside

Hi, I have a string like this, char str ="This, a sample string.\\nThis is the second line, \\n \\n, we will have one blank line"; if I want to use strtok() to seperate the string, which token should I use? I tried "\n", "\\n", either not working. peter (1 Reply)
Discussion started by: laopi
1 Replies

10. Shell Programming and Scripting

while and do problems

Any ideas how to clear this error as it seems I dont understand if,do,while and els commands #!/bin/ksh set -x print "This script creates test messages" print "Please enter test case name" read testcasename echo $testcasename skipfield=Y while print "Do you want to skip this field... (4 Replies)
Discussion started by: andrew.p.mcderm
4 Replies
Bio::Tools::Gel(3pm)					User Contributed Perl Documentation				      Bio::Tools::Gel(3pm)

NAME
Bio::Tools::Gel - Calculates relative electrophoretic migration distances SYNOPSIS
use Bio::PrimarySeq; use Bio::Restriction::Analysis; use Bio::Tools::Gel; # get a sequence my $d = 'AAAAAAAAAGAATTCTTTTTTTTTTTTTTGAATTCGGGGGGGGGGGGGGGGGGGG'; my $seq1 = Bio::Seq->new(-id=>'groundhog day',-seq=>$d); # cut it with an enzyme my $ra=Bio::Restriction::Analysis->new(-seq=>$seq1); @cuts = $ra->fragments('EcoRI'), 3; # analyse the fragments in a gel my $gel = Bio::Tools::Gel->new(-seq=>@cuts,-dilate=>10); my %bands = $gel->bands; foreach my $band (sort {$b <=> $a} keys %bands){ print $band," ", sprintf("%.1f", $bands{$band})," "; } #prints: #20 27.0 #25 26.0 #10 30.0 DESCRIPTION
This takes a set of sequences or Bio::Seq objects, and calculates their respective migration distances using: distance = dilation * (4 - log10(length(dna)); Source: Molecular Cloning, a Laboratory Manual. Sambrook, Fritsch, Maniatis. CSHL Press, 1989. Bio::Tools::Gel currently calculates migration distances based solely on the length of the nucleotide sequence. Secondary or tertiary structure, curvature, and other biophysical attributes of a sequence are currently not considered. Polypeptide migration is currently not supported. FEEDBACK
Mailing Lists User feedback is an integral part of the evolution of this and other Bioperl modules. Send your comments and suggestions preferably to the Bioperl mailing list. Your participation is much appreciated. bioperl-l@bioperl.org - General discussion http://bioperl.org/wiki/Mailing_lists - About the mailing lists Support Please direct usage questions or support issues to the mailing list: bioperl-l@bioperl.org rather than to the module maintainer directly. Many experienced and reponsive experts will be able look at the problem and quickly address it. Please include a thorough description of the problem with code and data examples if at all possible. Reporting Bugs Report bugs to the Bioperl bug tracking system to help us keep track of the bugs and their resolution. Bug reports can be submitted via the web: https://redmine.open-bio.org/projects/bioperl/ AUTHOR - Allen Day Email allenday@ucla.edu APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ new Title : new Usage : my $gel = Bio::Tools::Gel->new(-seq => $sequence,-dilate => 3); Function: Initializes a new Gel Returns : Bio::Tools::Gel Args : -seq => Bio::Seq(s), scalar(s) or list of either/both (default: none) -dilate => Expand band migration distances (default: 1) add_band Title : add_band Usage : $gel->add_band($seq); Function: Calls _add_band with a (possibly created) Bio::Seq object. Returns : Args : Bio::Seq, scalar sequence, or list of either/both. _add_band Title : _add_band Usage : $gel->_add_band($seq); Function: Adds a new band to the gel. Returns : Args : Bio::Seq object dilate Title : dilate Usage : $gel->dilate(1); Function: Sets/retrieves the dilation factor. Returns : dilation factor Args : Float or none bands Title : bands Usage : $gel->bands; Function: Calculates migration distances of sequences. Returns : hash of (seq_id => distance) Args : log10 Title : log10 Usage : log10($n); Function: returns base 10 log of $n. Returns : float Args : float perl v5.14.2 2012-03-02 Bio::Tools::Gel(3pm)
All times are GMT -4. The time now is 05:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy