Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9153147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:13:07+00:00 2026-06-17T12:13:07+00:00

i have the following code : int * buffer; buffer = (int *) malloc((320*240)*sizeof(int));

  • 0

i have the following code :

int * buffer;
buffer = (int *) malloc((320*240)*sizeof(int));

after populating the buffer with data i want to send it using UDP sockets, however it seems that currently my following send function sends just 4 byte (of data) and not ((320*240)*sizeof(int)):

iError = send(MySock, (char *)(buffer) , sizeof(buffer), 0);

i am tried different combinations on the second and third fields of the send function but it doesn’t work, What is the correct syntax should i use?

BTW i have to define the buffer as int * since it being used by other library that has to get that as int *.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:13:08+00:00Added an answer on June 17, 2026 at 12:13 pm

    This is because in your send() call, you specify sizeof (buffer). This is the size of the variable buffer, which is the size of a pointer, which happens to be four bytes on your system. It’s NOT the size of the block that the pointer points at, that information is not available.

    You must specify 320 * 240 * sizeof *buffer to get the proper size. Of course, even better is to factor this out into a variable:

    int *buffer;
    const size_t buffer_size = 320 * 240 * sizeof *buffer;
    
    if( (buffer = malloc(buffer_size)) != NULL )
    {
      /* ... fill buffer ... */
      send(MySock, buffer, buffer_size, 0);
    }
    

    There’s no need to cast, malloc() returns void * and send() accepts it.

    Note that doing very large send()s over UDP might not work, due to IP fragmentation. It’s better to send it using many small datagrams, in my experience.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: #include <string.h> int main(void) { char *buffer = NULL,
I have the following code: int send_cmd( int sock, char * buffer, int lbuffer
I have the following code populating a spinner, JSONObject jsonResponse = new JSONObject(new String(buffer));
I'm using ICSharpCode.SharpZipLib.dll for compress and decompress data. I have the following code that
I have the following code: int ircsocket_print(char *message, ...) { char buffer[512]; int iError;
Suppose I have the following Scala code: class Foo(a: Int) class Bar(b: Buffer[Int]) extends
I have the following code: StringBuilder data = new StringBuilder(); for (int i =
I have the following code: int sec = 62; string str = string.Format(Time: {0:xxx},
I have the following code: int width = 10; int height = 7; bool[,]
I have the following code: int i=1; printf((i==1)? : hello); printf( hello); And I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.