Search Results

Search found 27946 results on 1118 pages for 'output buffer empty'.

Page 153/1118 | < Previous Page | 149 150 151 152 153 154 155 156 157 158 159 160  | Next Page >

  • Progressively stream the output of an ASP.NET page - or render a page outside of an HTTP request

    - by Evgeny
    I have an ASP.NET 2.0 page with many repeating blocks, including a third-party server-side control (so it's not just plain HTML). Each is quite expensive to generate, in terms of both CPU and RAM. I'm currently using a standard Repeater control for this. There are two problems with this simple approach: The entire page must be rendered before any of it is returned to the client, so the user must wait a long time before they see any data. (I write progress messages using Response.Write, so there is feedback, but no actual results.) The ASP.NET worker process must hold everything in memory at the same time. There is no inherent needs for this: once one block is processed it won't be changed, so it could be returned to the client and the memory could be freed. I would like to somehow return these blocks to the client one at a time, as each is generated. I'm thinking of extracting the stuff inside the Repeater into a separate page and getting it repeatedly using AJAX, but there are some complications involved in that and I wonder if there is some simper approach. Ideally I'd like to keep it as one page (from the client's point of view), but return it incrementally. Another way would be to do something similar, but on the server: still create a separate page, but have the server access it and then Response.Write() the HTML it gets to the response stream for the real client request. Is there a way to avoid an HTTP request here, though? Is there some ASP.NET method that would render a UserControl or a Page outside of an HTTP request and simply return the HTML to me as a string? I'm open to other ideas on how to do this as well.

    Read the article

  • How do I output the preorder traversal of a tree given the inorder and postorder tranversal?

    - by user342580
    Given the code for outputing the postorder traversal of a tree when I have the preorder and the inorder traversal in an interger array. How do I similarily get the preorder with the inorder and postorder array given? void postorder( int preorder[], int prestart, int inorder[], int inostart, int length) { if(length==0) return; //terminating condition int i; for(i=inostart; i<inostart+length; i++) if(preorder[prestart]==inorder[i])//break when found root in inorder array break; postorder(preorder, prestart+1, inorder, inostart, i-inostart); postorder(preorder, prestart+i-inostart+1, inorder, i+1, length-i+inostart-1); cout<<preorder[prestart]<<" "; } Here is the prototype for preorder() void preorder( int inorderorder[], int inostart, int postorder[], int poststart, int length)

    Read the article

  • How do I output Unicode characters as a pair of ASCII characters?

    - by ChrisF
    How do I convert (as an example): Señor Coconut Y Su Conjunto - Introducciõn to: Señor Coconut Y Su Conjunto - Introducciõn I've got an app that creates m3u playlists, but when the track filename, artist or title contains non ASCII characters it doesn't get read properly by the music player so the track doesn't get played. I've discovered that if I write the track out as: #EXTINFUTF8:76,Señor Coconut Y Su Conjunto - Introducciõn #EXTINF:76,Señor Coconut Y Su Conjunto - Introducciõn #UTF8:01-Introducciõn.mp3 01-Introducciõn.mp3 Then the music player will read it correctly and play the track. My problem is that I can't find the information I need to be able to do the conversion properly.

    Read the article

  • Java: Combination of recursive loops which has different FOR loop inside; Output: FOR loops indexes

    - by vvinjj
    currently recursion is fresh & difficult topic for me, however I need to use it in one of my algorithms. Here is the challenge: I need a method where I specify number of recursions (number of nested FOR loops) and number of iterations for each FOR loop. The result should show me, something simmilar to counter, however each column of counter is limited to specific number. ArrayList<Integer> specs= new ArrayList<Integer>(); specs.add(5); //for(int i=0 to 5; i++) specs.add(7); specs.add(9); specs.add(2); specs.add(8); specs.add(9); public void recursion(ArrayList<Integer> specs){ //number of nested loops will be equal to: specs.size(); //each item in specs, specifies the For loop max count e.g: //First outside loop will be: for(int i=0; i< specs.get(0); i++) //Second loop inside will be: for(int i=0; i< specs.get(1); i++) //... } The the results will be similar to outputs of this manual, nested loop: int[] i; i = new int[7]; for( i[6]=0; i[6]<5; i[6]++){ for( i[5]=0; i[5]<7; i[5]++){ for(i[4] =0; i[4]<9; i[4]++){ for(i[3] =0; i[3]<2; i[3]++){ for(i[2] =0; i[2]<8; i[2]++){ for(i[1] =0; i[1]<9; i[1]++){ //... System.out.println(i[1]+" "+i[2]+" "+i[3]+" "+i[4]+" "+i[5]+" "+i[6]); } } } } } } I already, killed 3 days on this, and still no results, was searching it in internet, however the examples are too different. Therefore, posting the programming question in internet first time in my life. Thank you in advance, you are free to change the code efficiency, I just need the same results.

    Read the article

  • MySQL Query, limit output display according/only to associated ID!

    - by Jess
    So here's my situation. I have a books table and authors table. An author can have many books... In my authors page view, the user (logged in) can click an author in a tabled row and be directed to a page displaying the author's books (collected like this URI format: viewauthorbooks.php?author_id=23), very straight forward... However, in my query, I need to display the books for the author only, and not all books stored in the books table (as i currently have!) As I am a complete novice, I used the most simple query of: SELECT * FROM tasks_tb :)....this returns the books for me, but returns every single value (book) in the database, and not ones associated with the selected author. And when I click a different author the same books are displayed for them...I think everyone gets what I'm trying to achieve, I just don't know how to perform the query. I'm guessing that I need to start using more advanced query clauses like INNER JOIN etc. Anyone care to help me out :)

    Read the article

  • Real Time Sound Captureing J2ME

    - by Abdul jalil
    i am capturing sound in J2me and send these bytes to remote system, i then play these bytes on remote system.five second voice is capture and send to remote system. i get the repeated sound again .i am making a sound messenger please help me where i am doing wrong i am using the follown code . String remoteTimeServerAddress="192.168.137.179"; sc = (SocketConnection) Connector.open("socket://"+remoteTimeServerAddress+":13"); p = Manager.createPlayer("capture://audio?encoding=pcm&rate=11025&bits=16&channels=1"); p.realize(); RecordControl rc = (RecordControl)p.getControl("RecordControl"); ByteArrayOutputStream output = new ByteArrayOutputStream(); OutputStream outstream =sc.openOutputStream(); rc.setRecordStream(output); rc.startRecord(); p.start(); int size=output.size(); int offset=0; while(true) { Thread.currentThread().sleep(5000); rc.commit(); output.flush(); size=output.size(); if(size0) { recordedSoundArray=output.toByteArray(); outstream.write(recordedSoundArray,0,size); } output.reset(); rc.reset(); rc.setRecordStream(output); rc.startRecord(); }

    Read the article

  • Can I avoid a threaded UDP socket in Python dropping data?

    - by 666craig
    First off, I'm new to Python and learning on the job, so be gentle! I'm trying to write a threaded Python app for Windows that reads data from a UDP socket (thread-1), writes it to file (thread-2), and displays the live data (thread-3) to a widget (gtk.Image using a gtk.gdk.pixbuf). I'm using queues for communicating data between threads. My problem is that if I start only threads 1 and 3 (so skip the file writing for now), it seems that I lose some data after the first few samples. After this drop it looks fine. Even by letting thread 1 complete before running thread 3, this apparent drop is still there. Apologies for the length of code snippet (I've removed the thread that writes to file), but I felt removing code would just prompt questions. Hope someone can shed some light :-) import socket import threading import Queue import numpy import gtk gtk.gdk.threads_init() import gtk.glade import pygtk class readFromUDPSocket(threading.Thread): def __init__(self, socketUDP, readDataQueue, packetSize, numScans): threading.Thread.__init__(self) self.socketUDP = socketUDP self.readDataQueue = readDataQueue self.packetSize = packetSize self.numScans = numScans def run(self): for scan in range(1, self.numScans + 1): buffer = self.socketUDP.recv(self.packetSize) self.readDataQueue.put(buffer) self.socketUDP.close() print 'myServer finished!' class displayWithGTK(threading.Thread): def __init__(self, displayDataQueue, image, viewArea): threading.Thread.__init__(self) self.displayDataQueue = displayDataQueue self.image = image self.viewWidth = viewArea[0] self.viewHeight = viewArea[1] self.displayData = numpy.zeros((self.viewHeight, self.viewWidth, 3), dtype=numpy.uint16) def run(self): scan = 0 try: while True: if not scan % self.viewWidth: scan = 0 buffer = self.displayDataQueue.get(timeout=0.1) self.displayData[:, scan, 0] = numpy.fromstring(buffer, dtype=numpy.uint16) self.displayData[:, scan, 1] = numpy.fromstring(buffer, dtype=numpy.uint16) self.displayData[:, scan, 2] = numpy.fromstring(buffer, dtype=numpy.uint16) gtk.gdk.threads_enter() self.myPixbuf = gtk.gdk.pixbuf_new_from_data(self.displayData.tostring(), gtk.gdk.COLORSPACE_RGB, False, 8, self.viewWidth, self.viewHeight, self.viewWidth * 3) self.image.set_from_pixbuf(self.myPixbuf) self.image.show() gtk.gdk.threads_leave() scan += 1 except Queue.Empty: print 'myDisplay finished!' pass def quitGUI(obj): print 'Currently active threads: %s' % threading.enumerate() gtk.main_quit() if __name__ == '__main__': # Create socket (IPv4 protocol, datagram (UDP)) and bind to address socketUDP = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) host = '192.168.1.5' port = 1024 socketUDP.bind((host, port)) # Data parameters samplesPerScan = 256 packetsPerSecond = 1200 packetSize = 512 duration = 1 # For now, set a fixed duration to log data numScans = int(packetsPerSecond * duration) # Create array to store data data = numpy.zeros((samplesPerScan, numScans), dtype=numpy.uint16) # Create queue for displaying from readDataQueue = Queue.Queue(numScans) # Build GUI from Glade XML file builder = gtk.Builder() builder.add_from_file('GroundVue.glade') window = builder.get_object('mainwindow') window.connect('destroy', quitGUI) view = builder.get_object('viewport') image = gtk.Image() view.add(image) viewArea = (1200, samplesPerScan) # Instantiate & start threads myServer = readFromUDPSocket(socketUDP, readDataQueue, packetSize, numScans) myDisplay = displayWithGTK(readDataQueue, image, viewArea) myServer.start() myDisplay.start() gtk.gdk.threads_enter() gtk.main() gtk.gdk.threads_leave() print 'gtk.main finished!'

    Read the article

  • Bash: Is it ok to use same input file as output of a piped command?

    - by Amro
    Consider something like: cat file | command > file Is this good practice? Could this overwrite the input file as the same time as we are reading it, or is it always read first in memory then piped to second command? Obviously I can use temp files as intermediary step, but I'm just wondering.. t=$(mktemp) cat file | command > ${t} && mv ${t} file

    Read the article

  • Why in the following code the output is different when I compile or run it more than once

    - by Sanjeev
    class Name implements Runnable { public void run() { for (int x = 1; x <= 3; x++) { System.out.println("Run by " + Thread.currentThread().getName() + ", x is " + x); } } } public class Threadtest { public static void main(String [] args) { // Make one Runnable Name nr = new Name(); Thread one = new Thread(nr); Thread two = new Thread(nr); Thread three = new Thread(nr); one.setName("A"); two.setName("B"); three.setName("C"); one.start(); two.start(); three.start(); } } The answer is different while compiling and running more then one time I don't know why? any idea.

    Read the article

  • Efficient file buffering & scanning methods for large files in python

    - by eblume
    The description of the problem I am having is a bit complicated, and I will err on the side of providing more complete information. For the impatient, here is the briefest way I can summarize it: What is the fastest (least execution time) way to split a text file in to ALL (overlapping) substrings of size N (bound N, eg 36) while throwing out newline characters. I am writing a module which parses files in the FASTA ascii-based genome format. These files comprise what is known as the 'hg18' human reference genome, which you can download from the UCSC genome browser (go slugs!) if you like. As you will notice, the genome files are composed of chr[1..22].fa and chr[XY].fa, as well as a set of other small files which are not used in this module. Several modules already exist for parsing FASTA files, such as BioPython's SeqIO. (Sorry, I'd post a link, but I don't have the points to do so yet.) Unfortunately, every module I've been able to find doesn't do the specific operation I am trying to do. My module needs to split the genome data ('CAGTACGTCAGACTATACGGAGCTA' could be a line, for instance) in to every single overlapping N-length substring. Let me give an example using a very small file (the actual chromosome files are between 355 and 20 million characters long) and N=8 import cStringIO example_file = cStringIO.StringIO("""\ header CAGTcag TFgcACF """) for read in parse(example_file): ... print read ... CAGTCAGTF AGTCAGTFG GTCAGTFGC TCAGTFGCA CAGTFGCAC AGTFGCACF The function that I found had the absolute best performance from the methods I could think of is this: def parse(file): size = 8 # of course in my code this is a function argument file.readline() # skip past the header buffer = '' for line in file: buffer += line.rstrip().upper() while len(buffer) = size: yield buffer[:size] buffer = buffer[1:] This works, but unfortunately it still takes about 1.5 hours (see note below) to parse the human genome this way. Perhaps this is the very best I am going to see with this method (a complete code refactor might be in order, but I'd like to avoid it as this approach has some very specific advantages in other areas of the code), but I thought I would turn this over to the community. Thanks! Note, this time includes a lot of extra calculation, such as computing the opposing strand read and doing hashtable lookups on a hash of approximately 5G in size. Post-answer conclusion: It turns out that using fileobj.read() and then manipulating the resulting string (string.replace(), etc.) took relatively little time and memory compared to the remainder of the program, and so I used that approach. Thanks everyone!

    Read the article

  • Why isn't my log4net appender buffering?

    - by Eric
    I've created a custom log4net appender. It descends from log4net.Appender.SmtpAppender which descends from log4net.Appender.BufferingAppenderSkeleton. I programatically setup the following parameters in its constructor: this.Lossy = false; //don't drop any messages this.BufferSize = 3; //buffer up to 3 messages this.Threshold = log4net.Core.Level.Error; //append messages of Error or higher this.Evaluator = new log4net.Core.LevelEvaluator(Level.Off); //don't flush the buffer for any message, regardless of level I expect this would buffer 3 events of level Error or higher and deliver those events when the buffer is filled. However, I'm finding that the events are not buffered at all; instead, SendBuffer() is called immediately every time an error is logged. Is there a mistake in my configuration? Thanks

    Read the article

  • Same IL code, different output - how is it possible?

    - by Hali
    When I compile this code with mono (gmcs) and run it, it outputs -1 (both with mono and .Net framework). When I compile it with VS (csc), it outputs -1 when I run it with mono, and 0 when I run it with the .Net framework. The code in question is: using System; public class Program { public static void Main() { Console.WriteLine(string.Compare("alo\0alo\0", "alo\0alo\0\0", false, System.Globalization.CultureInfo.InvariantCulture)); } } Compiled with VS: .method public hidebysig static void Main() cil managed { .entrypoint // Code size 29 (0x1d) .maxstack 8 IL_0000: nop IL_0001: ldstr bytearray (61 00 6C 00 6F 00 00 00 61 00 6C 00 6F 00 00 00 ) // a.l.o...a.l.o... IL_0006: ldstr bytearray (61 00 6C 00 6F 00 00 00 61 00 6C 00 6F 00 00 00 // a.l.o...a.l.o... 00 00 ) IL_000b: ldc.i4.0 IL_000c: call class [mscorlib]System.Globalization.CultureInfo [mscorlib]System.Globalization.CultureInfo::get_InvariantCulture() IL_0011: call int32 [mscorlib]System.String::Compare(string, string, bool, class [mscorlib]System.Globalization.CultureInfo) IL_0016: call void [mscorlib]System.Console::WriteLine(int32) IL_001b: nop IL_001c: ret } // end of method Program::Main Compiled with mono: .method public hidebysig static void Main() cil managed { .entrypoint // Code size 27 (0x1b) .maxstack 8 IL_0000: ldstr bytearray (61 00 6C 00 6F 00 00 00 61 00 6C 00 6F 00 00 00 ) // a.l.o...a.l.o... IL_0005: ldstr bytearray (61 00 6C 00 6F 00 00 00 61 00 6C 00 6F 00 00 00 // a.l.o...a.l.o... 00 00 ) IL_000a: ldc.i4.0 IL_000b: call class [mscorlib]System.Globalization.CultureInfo [mscorlib]System.Globalization.CultureInfo::get_InvariantCulture() IL_0010: call int32 [mscorlib]System.String::Compare(string, string, bool, class [mscorlib]System.Globalization.CultureInfo) IL_0015: call void [mscorlib]System.Console::WriteLine(int32) IL_001a: ret } // end of method Program::Main The only difference is the two extra NOP instructions in the VS version. How is it possible?

    Read the article

  • Stored procedure with output parameters vs. table-valued function?

    - by abatishchev
    Which approach is better to use if I need a member (sp or func) returning 2 parameters: CREATE PROCEDURE Test @in INT, @outID INT OUT, @amount DECIMAL OUT AS BEGIN ... END or CREATE FUNCTION Test ( @in INT ) RETURNS @ret TABLE (outID INT, amount DECIMAL) AS BEGIN ... END What are pros and cons of each approach considering that the result will passed to another stored procedure: EXEC Foobar @outID, @outAmount

    Read the article

  • What happens when we say "listen to a port" ?

    - by smwikipedia
    Hi, When we start a server application, we always need to speicify the port number it listens to. But how is this "listening mechanism" implemented under the hood? My current imagination is like this: The operating system associate the port number with some buffer. The server application's responsibiligy is to monitor this buffer. If there's no data in this buffer, the server application's listen operation will just block the application. When some data arrives from the wire, the operating system will know that check the data and see if it is targed at this port number. And then it will fill the buffer. And then OS will notify the blocked server application and the server application will get the data and continue to run. Question is: If the above scenario is correct, how could the opearting system know there's data arriving from wire? It cannot be a busy pooling. Is it some kind of interrupt-based mechanism? If there's too much data arriving and the buffer is not big enough, will there be data loss? Is the "listen to a port" operation really a blocking operation? Many thanks.

    Read the article

  • reading and writing QByteArrays

    - by synchronicity
    I'm having trouble reading and writing QByteArray data to a file. My goal is to save QPixmap data into a QByteArray and save that QByteArray to a file (with the ability to read this QByteArray back from the file and into a QPixmap). I want to use following code from the QPixmap documentation: QPixmap pixmap(<image path>); QByteArray bytes; QBuffer buffer(&bytes); buffer.open(QIODevice::WriteOnly); pixmap.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format After writing the buffer to a file, I want to be able to retrieve the QByteArray and load it back into a QPixmap using the QPixmap::loadFromData() function. Please let me know if any further clarification is needed (I'm open to alternative approaches as well, I just need to be able to read and write the QPixmap to a file! :) );

    Read the article

  • How do you send a named pipe string from umnanaged to managed code space?

    - by billmcf
    I appear to have a named pipes 101 issue. I have a very simple set up to connect a simplex named pipe transmitting from a C++ unmanaged app to a C# managed app. The pipe connects, but I cannot send a "message" through the pipe unless I close the handle which appears to flush the buffer and pass the message through. It's like the message is blocked. I have tried reversing the roles of client/server and invoking them with different Flag combinations without any luck. I can easily send messages in the other direction from C# managed to C++ unmanaged. Does anyone have any insight. Can any of you guys successfully send messages from C++ unmanaged to C# managed? I can find plenty of examples of intra amanged or unmanaged pipes but not inter managed to/from unamanged - just claims to be able to do it. In the listings, I have omitted much of the wrapper stuff for clarity. The key bits I believe that are relevant are the pipe connection/creation/read and write methods. Don't worry too much about blocking/threading here. C# Server side // This runs in its own thread and so it is OK to block private void ConnectToClient() { // This server will listen to the sending client if (m_InPipeStream == null) { m_InPipeStream = new NamedPipeServerStream("TestPipe", PipeDirection.In, 1); } // Wait for client to connect to our server m_InPipeStream.WaitForConnection(); // Verify client is running if (!m_InPipeStream.IsConnected) { return; } // Start listening for messages on the client stream if (m_InPipeStream != null && m_InPipeStream.CanRead) { ReadThread = new Thread(new ParameterizedThreadStart(Read)); ReadThread.Start(m_InPipeStream); } } // This runs in its own thread and so it is OK to block private void Read(object serverObj) { NamedPipeServerStream pipeStream = (NamedPipeServerStream)serverObj; using (StreamReader sr = new StreamReader(pipeStream)) { while (true) { string buffer = "" ; try { // Blocks here until the handle is closed by the client-side!! buffer = sr.ReadLine(); // <<<<<<<<<<<<<< Sticks here } catch { // Read error break; } // Client has disconnected? if (buffer == null || buffer.Length == 0) break; // Fire message received event if message is non-empty if (MessageReceived != null && buffer != "") { MessageReceived(buffer); } } } } C++ client side // Static - running in its own thread. DWORD CNamedPipe::ListenForServer(LPVOID arg) { // The calling app (this) is passed as the parameter CNamedPipe* app = (CNamedPipe*)arg; // Out-Pipe: connect as a client to a waiting server app->m_hOutPipeHandle = CreateFile("\\\\.\\pipe\\TestPipe", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); // Could not create handle if (app->m_hInPipeHandle == NULL || app->m_hInPipeHandle == INVALID_HANDLE_VALUE) { return 1; } return 0; } // Sends a message to the server BOOL CNamedPipe::SendMessage(CString message) { DWORD dwSent; if (m_hOutPipeHandle == NULL || m_hOutPipeHandle == INVALID_HANDLE_VALUE) { return FALSE; } else { BOOL bOK = WriteFile(m_hOutPipeHandle, message, message.GetLength()+1, &dwSent, NULL); //FlushFileBuffers(m_hOutPipeHandle); // <<<<<<< Tried this return (!bOK || (message.GetLength()+1) != dwSent) ? FALSE : TRUE; } } // Somewhere in the Windows C++/MFC code... ... // This write is non-blocking. It just passes through having loaded the pipe. m_pNamedPipe->SendMessage("Hi de hi"); ...

    Read the article

  • get content from website with utf8 format

    - by zahir
    i want how to get the content from websites with utf8 format,, i have writing the following code is try { String webnames = "http://pathivu.com"; URL url = new URL(webnames); URLConnection urlc = url.openConnection(); //BufferedInputStream buffer = new BufferedInputStream(urlc.getInputStream()); BufferedReader buffer = new BufferedReader(new InputStreamReader(urlc.getInputStream(), "UTF8")); StringBuilder builder = new StringBuilder(); int byteRead; while ((byteRead = buffer.read()) != -1) builder.append((char) byteRead); buffer.close(); String text=builder.toString(); System.out.println(text); } catch (IOException e) { e.printStackTrace(); } but i cant get the correct format... thanks and advance..

    Read the article

  • Is it possible to use SQL XML to insert, and get output from each record?

    - by nbolton
    I would like to perform a SQL XML insert (on MSSQL), and in this case I need to insert a list of files into the DB (this is simple enough). However, there's an auto generated PK column (ID), and I need the ID for each newly created filename without performing a 2nd query. Is this possible? I guess it doesn't matter if the result is/isn't XML, but the input certainly has to be.

    Read the article

  • Using the filename for GET data and making the PHP page output as a JPG extension?

    - by Rob
    Alright, currently I'm using GD to create a PNG image that logs a few different things, depending on the GET data, for example: http://example.com/file.php?do=this will log one thing while http://example.com/file.php?do=that will log another thing. However, I'd like to do it without GET data, so instead http://example.com/dothis.php will log one thing, and http://example.com/dothat.php will log the other. But on top of that, I'd also like to make it accessible via the JPG file extension. I've seen this done but I can't figure out how. So that way http://example.com/dothis.JPG will log one thing, while http://example.com/dothat.JPG logs the other. The logging part is simple, of course. I simple need to know how to use filenames in place of the GET data and how to set the php file to be accessible via a jpg file extension.

    Read the article

  • public class ImageHandler : IHttpHandler

    - by Ken
    cmd.Parameters.AddWithValue("@id", new system.Guid (imageid)); What using System reference would this require? Here is the handler: using System; using System.Collections.Specialized; using System.Web; using System.Web.Configuration; using System.Web.Security; using System.Globalization; using System.Configuration; using System.Data.SqlClient; using System.Data; using System.IO; using System.Web.Profile; using System.Drawing; public class ImageHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { string imageid; if (context.Request.QueryString["id"] != null) imageid = (context.Request.QueryString["id"]); else throw new ArgumentException("No parameter specified"); context.Response.ContentType = "image/jpeg"; Stream strm = ShowProfileImage(imageid.ToString()); byte[] buffer = new byte[8192]; int byteSeq = strm.Read(buffer, 0, 8192); while (byteSeq > 0) { context.Response.OutputStream.Write(buffer, 0, byteSeq); byteSeq = strm.Read(buffer, 0, 8192); } //context.Response.BinaryWrite(buffer); } public Stream ShowProfileImage(String imageid) { string conn = ConfigurationManager.ConnectionStrings["MyConnectionString1"].ConnectionString; SqlConnection connection = new SqlConnection(conn); string sql = "SELECT image FROM Profile WHERE UserId = @id"; SqlCommand cmd = new SqlCommand(sql, connection); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@id", new system.Guid (imageid));//Failing Here!!!! connection.Open(); object img = cmd.ExecuteScalar(); try { return new MemoryStream((byte[])img); } catch { return null; } finally { connection.Close(); } } public bool IsReusable { get { return false; } } }

    Read the article

  • char[] and char* compatibility?

    - by Aerovistae
    In essence, will this code work? And before you say "Run it and see!", I just realized my cygwin didn't come with gcc and it's currently 40 minutes away from completing reinstallation. That being said: char* words[1000]; for(int i = 0; i<1000; i++) words[i] = NULL; char buffer[ 1024 ]; //omit code that places "ADD splash\0" into the buffer if(strncmp (buffer, "ADD ", 4){ char* temp = buffer + 4; printf("Adding: %s", temp); int i = 0; while(words[i] != NULL) i++; words[i] = temp; } I'm mostly uncertain about the line char* temp = buffer + 4, and also whether I can assign words[i] in the manner that I am. Am I going to get type errors when I eventually try to compile this in 40 minutes? Also-- if this works, why don't I need to use malloc() on each element of words[]? Why can I say words[i] = temp, instead of needing to allocate memory for words[i] the length of temp?

    Read the article

  • how to change type of value in an php array and sorting it..is it possible ?

    - by justjoe
    hi, i got problem with my code and hopefully someone able to figure it out. The main purpose is to sort array based on its value (then reindex its numerical key). i got this sample of filename : $filename = array("index 198.php", "index 192.php", "index 144.php", "index 2.php", "index 1.php", "index 100.php", "index 111.php"); $alloutput = array(); //all of index in array foreach ($filename as $name) { preg_match('#(\d+)#', $name, $output); // take only the numerical from file name array_shift($output); // cleaned. the last code create duplicate numerical in $output, if (is_array($hasilku)) { $alloutput = array_merge($alloutput, $output); } } //try to check the type of every value in array foreach ($alloutput as $output) { if (is_array($hasil)) { echo "array true </br>"; } elseif (is_int($hasil)) { echo "integer true </br>"; } elseif (is_string($hasil)) { //the numerical taken from filename always resuld "string". echo "string true </br>"; } } the output of this code will be : Array ( [0] = 198 [1] = 192 [2] = 144 [3] = 2 [4] = 1 [5] = 100 [6] = 111 ) i have test every output in array. It's all string (and not numerical), So the question is how to change this string to integer, so i can sort it from the lowest into the highest number ? the main purpose of this code is how to output array where it had been sort from lowest to highest ?

    Read the article

  • Performance Cost of a Memcopy in C/C++

    - by Cenoc
    So whenever I write code I always think about the performance implications. I've often wondered, what is the "cost" of using a memcopy relative to other functions in terms of performance? For example, I may be writing a sequence of numbers to a static buffer and concentrate on a frame within the buffer, in order to keep the frame once I get to the end of the buffer, I might memcopy all of it to the beginning OR I can implement an algorithm to amortize the computation.

    Read the article

< Previous Page | 149 150 151 152 153 154 155 156 157 158 159 160  | Next Page >