Reducing the size of a function don't work

Hi everybody,
I use Attiny84 which have low flash memory, and i'm not far the limit, so i tried to reduce size of some function. I have a function which use free() & and malloc to save RAM which look like this :

uint8_t * send = NULL;
void Function(int val)
  {
      if (send)
          free(send);
      
      send = (uint8_t*) malloc((val) * sizeof(uint8_t));
      send[3] = val;
  }

void setup() {}

void loop() {
  Function(5);
}

It take 894B on Attiny84 with no bootloader, if i remove Function, it take 246B. So i can conclude that Function() take 648B

If i remove free() :

uint8_t * send = NULL;
void Function(int val)
  {
      if (!send)
          send = (uint8_t*) malloc((val) * sizeof(uint8_t));
      
      
      send[3] = val;
  }

void setup() {}

void loop() {
  Function(5);
}

It take 898B so ... 4B more ? Not calling the Free() add 4B, should be less ?

BUT if i remove the condition :

uint8_t * send = NULL;
void Function(int val)
  {
          send = (uint8_t*) malloc((val) * sizeof(uint8_t));
      
      
      send[3] = val;
  }

void setup() {}

void loop() {
  Function(5);
}

It take 246B ...
I don't understand how a "if (send)" can take some much space ?

Code takes space. Instructions are stored in flash, too.
Also, don't confuse RAM use with flash use.

It probably doesn't; I bet the compiler optimizes the entire function away if you leave out the if (send) bit because nothing really happens there anyway.

Also, keep in mind that malloc() and free() may not offer much/any benefit if the variables involved only exist in the local scope of the function. In my experience, they rarely (if ever) really help in code optimization, and/or gains in other areas vastly outstrip the benefits.

Compilers nowadays do a lot of optimisation. You will have to look at the assembly code to find out what is exactly happening. E.g. functions might no longer be functions in the assembly but changing something might make them functions again.

Note that you don't safe memory by allocating memory and not immediately freeing it once it's no longer used. In your scenario you it's allocated but stays allocated till your function is called again (so back in loop() it's still allocated. In a real life scenario it might be possibly allocated for an hour (who knows, we don't have the complete picture) and freed only when the function is called again; so no gain and only pain.

One additional comment: you never check the result of malloc().

Thanks for your answers. It's a small sketch about the problem, its not really the function.

uint8_t * send = NULL;

is a global var, i don't know the size at the init, but after the size don't change. So reallocating at each call make no real sense. But in fact it save me 4B.
I understand that the compiler make optimisation but in that case i loose space :wink:
I will take a look at assembly :confused:

If i put the 'if (send)' after the malloc, it's 246B. \o/

i don't see where send [] is used, but repeatedly allocating and freeing it is inefficient and can be commonly be done by dynamically allocating it within the function. Can send be used solely while the function is invoked? Can the space allocated for send be reused in subsequent invocations of the function?

instead of alloc/freeing, for example, here's a function that dynamically allocates a 20 char string to display some global variables. the 20 char array is allocated on the stack when the function is invoked, and deallocated when the function completes

int a;
int b;
const char *txt = "text";

void disp () {
    char s [20];
    sprintf (s, " %3d, %3d %s\n", a, b, txt);
    Serial.println (s);
}
1 Like

And in fact, that's often the quickest way to save space - verify if you're using the appropriate optimization flags.

Another way to save lots of space is to forego Arduino altogether. Evidently, this is a less user-friendly approach, but if you're willing to root through assembly, I assume you're also capable of setting up a project in e.g. Microchip Studio. Especially when working on (AT)tiny platforms, it can make sense to cut off all the overhead and only use the bare necessities.

1 Like

Thx for answers.

Yep, it uses -Os flag. I used to write some x86 & 68000 asm code, but was long time ago.
I tried different way to cheat the compiler, but at the end, it changes nothing.

It's look like the first time i use the var "send" as reading that the sketch get much much bigger, like if the compiler check some stuff before reading or save data, or ... i will try to get a look into it
It's anywhere in the code in fact. If

If you use DrAzzy's core, you can get the assembly listing by using "export compiled binary".

Just to clarify, I wasn't suggesting to resort to writing asm. Just skipping the Arduino core and using a more elementary approach, but still in C and/or C++.

Of course, this is also not to stop you from optimizing Arduino code. By all means, see how efficient you can make it while still enjoying the accessibility and portability of Arduino.

Yep thx, I found it and the answer ... will surprise ^^

For this code (898B) :

uint8_t * send = NULL;
void Function(int val)
  {
    if (!send)
          send = (uint8_t*) malloc((val) * sizeof(uint8_t));
      
      
      send[3] = val;
  }

void setup() {}

void loop() {
  Function(5);
}

I get :


Disassembly of section .text:

00000000 <__vectors>:
__vectors():
   0:	10 c0       	rjmp	.+32     	; 0x22 <__ctors_end>
   2:	2a c0       	rjmp	.+84     	; 0x58 <__bad_interrupt>
   4:	29 c0       	rjmp	.+82     	; 0x58 <__bad_interrupt>
   6:	28 c0       	rjmp	.+80     	; 0x58 <__bad_interrupt>
   8:	27 c0       	rjmp	.+78     	; 0x58 <__bad_interrupt>
   a:	26 c0       	rjmp	.+76     	; 0x58 <__bad_interrupt>
   c:	25 c0       	rjmp	.+74     	; 0x58 <__bad_interrupt>
   e:	24 c0       	rjmp	.+72     	; 0x58 <__bad_interrupt>
  10:	23 c0       	rjmp	.+70     	; 0x58 <__bad_interrupt>
  12:	22 c0       	rjmp	.+68     	; 0x58 <__bad_interrupt>
  14:	21 c0       	rjmp	.+66     	; 0x58 <__bad_interrupt>
  16:	21 c0       	rjmp	.+66     	; 0x5a <__vector_11>
  18:	1f c0       	rjmp	.+62     	; 0x58 <__bad_interrupt>
  1a:	1e c0       	rjmp	.+60     	; 0x58 <__bad_interrupt>
  1c:	1d c0       	rjmp	.+58     	; 0x58 <__bad_interrupt>
  1e:	1c c0       	rjmp	.+56     	; 0x58 <__bad_interrupt>
  20:	1b c0       	rjmp	.+54     	; 0x58 <__bad_interrupt>

00000022 <__ctors_end>:
__trampolines_start():
  22:	11 24       	eor	r1, r1
  24:	1f be       	out	0x3f, r1	; 63
  26:	cf e5       	ldi	r28, 0x5F	; 95
  28:	d2 e0       	ldi	r29, 0x02	; 2
  2a:	de bf       	out	0x3e, r29	; 62
  2c:	cd bf       	out	0x3d, r28	; 61

0000002e <__do_clear_bss>:
__do_clear_bss():
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2441
  2e:	20 e0       	ldi	r18, 0x00	; 0
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2442
  30:	a6 e6       	ldi	r26, 0x66	; 102
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2443
  32:	b0 e0       	ldi	r27, 0x00	; 0
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2444
  34:	01 c0       	rjmp	.+2      	; 0x38 <.do_clear_bss_start>

00000036 <.do_clear_bss_loop>:
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2446
  36:	1d 92       	st	X+, r1

00000038 <.do_clear_bss_start>:
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2448
  38:	a5 37       	cpi	r26, 0x75	; 117
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2449
  3a:	b2 07       	cpc	r27, r18
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2450
  3c:	e1 f7       	brne	.-8      	; 0x36 <.do_clear_bss_loop>

0000003e <__do_copy_data>:
__do_copy_data():
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2409
  3e:	10 e0       	ldi	r17, 0x00	; 0
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2410
  40:	a0 e6       	ldi	r26, 0x60	; 96
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2411
  42:	b0 e0       	ldi	r27, 0x00	; 0
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2412
  44:	ec e7       	ldi	r30, 0x7C	; 124
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2413
  46:	f3 e0       	ldi	r31, 0x03	; 3
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2414
  48:	02 c0       	rjmp	.+4      	; 0x4e <__SREG__+0xf>
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2417
  4a:	05 90       	lpm	r0, Z+
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2422
  4c:	0d 92       	st	X+, r0
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2424
  4e:	a6 36       	cpi	r26, 0x66	; 102
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2425
  50:	b1 07       	cpc	r27, r17
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2426
  52:	d9 f7       	brne	.-10     	; 0x4a <__SREG__+0xb>
  54:	4c d0       	rcall	.+152    	; 0xee <main>
  56:	90 c1       	rjmp	.+800    	; 0x378 <_exit>

00000058 <__bad_interrupt>:
__vector_1():
  58:	d3 cf       	rjmp	.-90     	; 0x0 <__vectors>

0000005a <__vector_11>:
__vector_11():
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:308
      #error "cannot find Millis() timer overflow vector"
    #endif
  #else
    #error "Millis() timer not defined!"
  #endif
  {
  5a:	1f 92       	push	r1
  5c:	0f 92       	push	r0
  5e:	0f b6       	in	r0, 0x3f	; 63
  60:	0f 92       	push	r0
  62:	11 24       	eor	r1, r1
  64:	2f 93       	push	r18
  66:	3f 93       	push	r19
  68:	8f 93       	push	r24
  6a:	9f 93       	push	r25
  6c:	af 93       	push	r26
  6e:	bf 93       	push	r27
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:311
    // copy these to local variables so they can be stored in registers
    // (volatile variables must be read from memory on every access)
    unsigned long m = millis_timer_millis;
  70:	80 91 6d 00 	lds	r24, 0x006D	; 0x80006d <millis_timer_millis>
  74:	90 91 6e 00 	lds	r25, 0x006E	; 0x80006e <millis_timer_millis+0x1>
  78:	a0 91 6f 00 	lds	r26, 0x006F	; 0x80006f <millis_timer_millis+0x2>
  7c:	b0 91 70 00 	lds	r27, 0x0070	; 0x800070 <millis_timer_millis+0x3>
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:312
    unsigned char f = millis_timer_fract;
  80:	30 91 6c 00 	lds	r19, 0x006C	; 0x80006c <millis_timer_fract>
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:319
    static unsigned char correct_exact = 0;     // rollover intended
    if (++correct_exact < CORRECT_EXACT_MANY) {
      ++f;
    }
#endif
    f += FRACT_INC;
  84:	26 e0       	ldi	r18, 0x06	; 6
  86:	23 0f       	add	r18, r19
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:321

    if (f >= FRACT_MAX)
  88:	2d 37       	cpi	r18, 0x7D	; 125
  8a:	68 f1       	brcs	.+90     	; 0xe6 <__vector_11+0x8c>
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:323
    {
      f -= FRACT_MAX;
  8c:	29 e8       	ldi	r18, 0x89	; 137
  8e:	23 0f       	add	r18, r19
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:324
      m += MILLIS_INC + 1;
  90:	03 96       	adiw	r24, 0x03	; 3
  92:	a1 1d       	adc	r26, r1
  94:	b1 1d       	adc	r27, r1
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:331
    else
    {
      m += MILLIS_INC;
    }

    millis_timer_fract = f;
  96:	20 93 6c 00 	sts	0x006C, r18	; 0x80006c <millis_timer_fract>
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:332
    millis_timer_millis = m;
  9a:	80 93 6d 00 	sts	0x006D, r24	; 0x80006d <millis_timer_millis>
  9e:	90 93 6e 00 	sts	0x006E, r25	; 0x80006e <millis_timer_millis+0x1>
  a2:	a0 93 6f 00 	sts	0x006F, r26	; 0x80006f <millis_timer_millis+0x2>
  a6:	b0 93 70 00 	sts	0x0070, r27	; 0x800070 <millis_timer_millis+0x3>
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:334
#ifndef CORRECT_EXACT_MICROS
    millis_timer_overflow_count++;
  aa:	80 91 68 00 	lds	r24, 0x0068	; 0x800068 <millis_timer_overflow_count>
  ae:	90 91 69 00 	lds	r25, 0x0069	; 0x800069 <millis_timer_overflow_count+0x1>
  b2:	a0 91 6a 00 	lds	r26, 0x006A	; 0x80006a <millis_timer_overflow_count+0x2>
  b6:	b0 91 6b 00 	lds	r27, 0x006B	; 0x80006b <millis_timer_overflow_count+0x3>
  ba:	01 96       	adiw	r24, 0x01	; 1
  bc:	a1 1d       	adc	r26, r1
  be:	b1 1d       	adc	r27, r1
  c0:	80 93 68 00 	sts	0x0068, r24	; 0x800068 <millis_timer_overflow_count>
  c4:	90 93 69 00 	sts	0x0069, r25	; 0x800069 <millis_timer_overflow_count+0x1>
  c8:	a0 93 6a 00 	sts	0x006A, r26	; 0x80006a <millis_timer_overflow_count+0x2>
  cc:	b0 93 6b 00 	sts	0x006B, r27	; 0x80006b <millis_timer_overflow_count+0x3>
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:336
#endif
  }
  d0:	bf 91       	pop	r27
  d2:	af 91       	pop	r26
  d4:	9f 91       	pop	r25
  d6:	8f 91       	pop	r24
  d8:	3f 91       	pop	r19
  da:	2f 91       	pop	r18
  dc:	0f 90       	pop	r0
  de:	0f be       	out	0x3f, r0	; 63
  e0:	0f 90       	pop	r0
  e2:	1f 90       	pop	r1
  e4:	18 95       	reti
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:328
      f -= FRACT_MAX;
      m += MILLIS_INC + 1;
    }
    else
    {
      m += MILLIS_INC;
  e6:	02 96       	adiw	r24, 0x02	; 2
  e8:	a1 1d       	adc	r26, r1
  ea:	b1 1d       	adc	r27, r1
  ec:	d4 cf       	rjmp	.-88     	; 0x96 <__vector_11+0x3c>

000000ee <main>:
main():
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:1138
*/

  // Use the Millis Timer for fast PWM (unless it doesn't have an output).
  #if (TIMER_TO_USE_FOR_MILLIS == 0)
    #if defined(WGM01) // if Timer0 has PWM
      TCCR0A = (1<<WGM01) | (1<<WGM00);
  ee:	83 e0       	ldi	r24, 0x03	; 3
  f0:	80 bf       	out	0x30, r24	; 48
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:1141
    #endif
    #if defined(TCCR0B) //The x61 has a wacky Timer0!
      TCCR0B = (MillisTimer_Prescale_Index << CS00);
  f2:	83 bf       	out	0x33, r24	; 51
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:1162
    TCCR1A = 1<<WGM10;
    TCCR1B = (1<<WGM12) | (MillisTimer_Prescale_Index << CS10);
  #endif

  // this needs to be called before setup() or some functions won't work there
  sei();
  f4:	78 94       	sei
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:1169
  #ifndef DISABLEMILLIS
    // Enable the overflow interrupt (this is the basic system tic-toc for millis)
    #if defined(TIMSK) && defined(TOIE0) && (TIMER_TO_USE_FOR_MILLIS == 0)
      sbi(TIMSK, TOIE0);
    #elif defined(TIMSK0) && defined(TOIE0) && (TIMER_TO_USE_FOR_MILLIS == 0)
      sbi(TIMSK0, TOIE0);
  f6:	99 b7       	in	r25, 0x39	; 57
  f8:	91 60       	ori	r25, 0x01	; 1
  fa:	99 bf       	out	0x39, r25	; 57
initToneTimerInternal():
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:972
    #elif (TIMER_TO_USE_FOR_TONE == 1 ) && defined(__AVR_ATtinyX7__)
      TCCR1A = (1<<COM1A1)|(1<<COM1B1)|(1<<WGM10);
      TCCR1B = (ToneTimer_Prescale_Index << CS10);
    #elif (TIMER_TO_USE_FOR_TONE == 1) // x4, x8, x313,
      // Use the Tone Timer for phase correct PWM
      TCCR1A = (1<<WGM10);
  fc:	91 e0       	ldi	r25, 0x01	; 1
  fe:	9f bd       	out	0x2f, r25	; 47
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:973
      TCCR1B = (0<<WGM12) | (0<<WGM13) | (ToneTimer_Prescale_Index << CS10); //set the clock
 100:	8e bd       	out	0x2e, r24	; 46
main():
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:1214
  #if defined( INITIALIZE_ANALOG_TO_DIGITAL_CONVERTER ) && INITIALIZE_ANALOG_TO_DIGITAL_CONVERTER
    #if defined(ADCSRA)
      // set a2d prescale factor
      // ADCSRA = (ADCSRA & ~((1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0))) | (ADC_ARDUINO_PRESCALER << ADPS0) | (1<<ADEN);
      // dude, this is being called on startup. We know that ADCSRA is 0! Why add a RMW cycle?!
      ADCSRA = (ADC_ARDUINO_PRESCALER << ADPS0) | (1<<ADEN);
 102:	86 e8       	ldi	r24, 0x86	; 134
 104:	86 b9       	out	0x06, r24	; 6
Function():
\Arduino\test_composant\test_free_malloc/test_free_malloc.ino:8
  {
    if (!send)
          send = (uint8_t*) malloc((val) * sizeof(uint8_t));
      
      
      send[3] = val;
 106:	c5 e0       	ldi	r28, 0x05	; 5
\Arduino\test_composant\test_free_malloc/test_free_malloc.ino:4
uint8_t * send = NULL;
void Function(int val)
  {
    if (!send)
 108:	80 91 66 00 	lds	r24, 0x0066	; 0x800066 <__data_end>
 10c:	90 91 67 00 	lds	r25, 0x0067	; 0x800067 <__data_end+0x1>
 110:	89 2b       	or	r24, r25
 112:	39 f4       	brne	.+14     	; 0x122 <main+0x34>
\Arduino\test_composant\test_free_malloc/test_free_malloc.ino:5
          send = (uint8_t*) malloc((val) * sizeof(uint8_t));
 114:	85 e0       	ldi	r24, 0x05	; 5
 116:	90 e0       	ldi	r25, 0x00	; 0
 118:	0a d0       	rcall	.+20     	; 0x12e <malloc>
 11a:	90 93 67 00 	sts	0x0067, r25	; 0x800067 <__data_end+0x1>
 11e:	80 93 66 00 	sts	0x0066, r24	; 0x800066 <__data_end>
\Arduino\test_composant\test_free_malloc/test_free_malloc.ino:8
      
      
      send[3] = val;
 122:	e0 91 66 00 	lds	r30, 0x0066	; 0x800066 <__data_end>
 126:	f0 91 67 00 	lds	r31, 0x0067	; 0x800067 <__data_end+0x1>
 12a:	c3 83       	std	Z+3, r28	; 0x03
 12c:	ed cf       	rjmp	.-38     	; 0x108 <main+0x1a>

0000012e <malloc>:
malloc():
 12e:	0f 93       	push	r16
 130:	1f 93       	push	r17
 132:	cf 93       	push	r28
 134:	df 93       	push	r29
 136:	82 30       	cpi	r24, 0x02	; 2
 138:	91 05       	cpc	r25, r1
 13a:	10 f4       	brcc	.+4      	; 0x140 <malloc+0x12>
 13c:	82 e0       	ldi	r24, 0x02	; 2
 13e:	90 e0       	ldi	r25, 0x00	; 0
 140:	e0 91 73 00 	lds	r30, 0x0073	; 0x800073 <__flp>
 144:	f0 91 74 00 	lds	r31, 0x0074	; 0x800074 <__flp+0x1>
 148:	30 e0       	ldi	r19, 0x00	; 0
 14a:	20 e0       	ldi	r18, 0x00	; 0
 14c:	b0 e0       	ldi	r27, 0x00	; 0
 14e:	a0 e0       	ldi	r26, 0x00	; 0
 150:	30 97       	sbiw	r30, 0x00	; 0
 152:	99 f4       	brne	.+38     	; 0x17a <malloc+0x4c>
 154:	21 15       	cp	r18, r1
 156:	31 05       	cpc	r19, r1
 158:	09 f4       	brne	.+2      	; 0x15c <malloc+0x2e>
 15a:	4a c0       	rjmp	.+148    	; 0x1f0 <malloc+0xc2>
 15c:	28 1b       	sub	r18, r24
 15e:	39 0b       	sbc	r19, r25
 160:	24 30       	cpi	r18, 0x04	; 4
 162:	31 05       	cpc	r19, r1
 164:	d8 f5       	brcc	.+118    	; 0x1dc <malloc+0xae>
 166:	8a 81       	ldd	r24, Y+2	; 0x02
 168:	9b 81       	ldd	r25, Y+3	; 0x03
 16a:	61 15       	cp	r22, r1
 16c:	71 05       	cpc	r23, r1
 16e:	89 f1       	breq	.+98     	; 0x1d2 <malloc+0xa4>
 170:	fb 01       	movw	r30, r22
 172:	93 83       	std	Z+3, r25	; 0x03
 174:	82 83       	std	Z+2, r24	; 0x02
 176:	fe 01       	movw	r30, r28
 178:	11 c0       	rjmp	.+34     	; 0x19c <malloc+0x6e>
 17a:	40 81       	ld	r20, Z
 17c:	51 81       	ldd	r21, Z+1	; 0x01
 17e:	02 81       	ldd	r16, Z+2	; 0x02
 180:	13 81       	ldd	r17, Z+3	; 0x03
 182:	48 17       	cp	r20, r24
 184:	59 07       	cpc	r21, r25
 186:	e0 f0       	brcs	.+56     	; 0x1c0 <malloc+0x92>
 188:	48 17       	cp	r20, r24
 18a:	59 07       	cpc	r21, r25
 18c:	99 f4       	brne	.+38     	; 0x1b4 <malloc+0x86>
 18e:	10 97       	sbiw	r26, 0x00	; 0
 190:	61 f0       	breq	.+24     	; 0x1aa <malloc+0x7c>
 192:	12 96       	adiw	r26, 0x02	; 2
 194:	0c 93       	st	X, r16
 196:	12 97       	sbiw	r26, 0x02	; 2
 198:	13 96       	adiw	r26, 0x03	; 3
 19a:	1c 93       	st	X, r17
 19c:	32 96       	adiw	r30, 0x02	; 2
 19e:	cf 01       	movw	r24, r30
 1a0:	df 91       	pop	r29
 1a2:	cf 91       	pop	r28
 1a4:	1f 91       	pop	r17
 1a6:	0f 91       	pop	r16
 1a8:	08 95       	ret
 1aa:	00 93 73 00 	sts	0x0073, r16	; 0x800073 <__flp>
 1ae:	10 93 74 00 	sts	0x0074, r17	; 0x800074 <__flp+0x1>
 1b2:	f4 cf       	rjmp	.-24     	; 0x19c <malloc+0x6e>
 1b4:	21 15       	cp	r18, r1
 1b6:	31 05       	cpc	r19, r1
 1b8:	51 f0       	breq	.+20     	; 0x1ce <malloc+0xa0>
 1ba:	42 17       	cp	r20, r18
 1bc:	53 07       	cpc	r21, r19
 1be:	38 f0       	brcs	.+14     	; 0x1ce <malloc+0xa0>
 1c0:	a9 01       	movw	r20, r18
 1c2:	db 01       	movw	r26, r22
 1c4:	9a 01       	movw	r18, r20
 1c6:	bd 01       	movw	r22, r26
 1c8:	df 01       	movw	r26, r30
 1ca:	f8 01       	movw	r30, r16
 1cc:	c1 cf       	rjmp	.-126    	; 0x150 <malloc+0x22>
 1ce:	ef 01       	movw	r28, r30
 1d0:	f9 cf       	rjmp	.-14     	; 0x1c4 <malloc+0x96>
 1d2:	90 93 74 00 	sts	0x0074, r25	; 0x800074 <__flp+0x1>
 1d6:	80 93 73 00 	sts	0x0073, r24	; 0x800073 <__flp>
 1da:	cd cf       	rjmp	.-102    	; 0x176 <malloc+0x48>
 1dc:	fe 01       	movw	r30, r28
 1de:	e2 0f       	add	r30, r18
 1e0:	f3 1f       	adc	r31, r19
 1e2:	81 93       	st	Z+, r24
 1e4:	91 93       	st	Z+, r25
 1e6:	22 50       	subi	r18, 0x02	; 2
 1e8:	31 09       	sbc	r19, r1
 1ea:	39 83       	std	Y+1, r19	; 0x01
 1ec:	28 83       	st	Y, r18
 1ee:	d7 cf       	rjmp	.-82     	; 0x19e <malloc+0x70>
 1f0:	20 91 71 00 	lds	r18, 0x0071	; 0x800071 <__brkval>
 1f4:	30 91 72 00 	lds	r19, 0x0072	; 0x800072 <__brkval+0x1>
 1f8:	23 2b       	or	r18, r19
 1fa:	41 f4       	brne	.+16     	; 0x20c <malloc+0xde>
 1fc:	20 91 62 00 	lds	r18, 0x0062	; 0x800062 <__malloc_heap_start>
 200:	30 91 63 00 	lds	r19, 0x0063	; 0x800063 <__malloc_heap_start+0x1>
 204:	30 93 72 00 	sts	0x0072, r19	; 0x800072 <__brkval+0x1>
 208:	20 93 71 00 	sts	0x0071, r18	; 0x800071 <__brkval>
 20c:	20 91 60 00 	lds	r18, 0x0060	; 0x800060 <__DATA_REGION_ORIGIN__>
 210:	30 91 61 00 	lds	r19, 0x0061	; 0x800061 <__DATA_REGION_ORIGIN__+0x1>
 214:	21 15       	cp	r18, r1
 216:	31 05       	cpc	r19, r1
 218:	41 f4       	brne	.+16     	; 0x22a <malloc+0xfc>
 21a:	2d b7       	in	r18, 0x3d	; 61
 21c:	3e b7       	in	r19, 0x3e	; 62
 21e:	40 91 64 00 	lds	r20, 0x0064	; 0x800064 <__malloc_margin>
 222:	50 91 65 00 	lds	r21, 0x0065	; 0x800065 <__malloc_margin+0x1>
 226:	24 1b       	sub	r18, r20
 228:	35 0b       	sbc	r19, r21
 22a:	e0 91 71 00 	lds	r30, 0x0071	; 0x800071 <__brkval>
 22e:	f0 91 72 00 	lds	r31, 0x0072	; 0x800072 <__brkval+0x1>
 232:	e2 17       	cp	r30, r18
 234:	f3 07       	cpc	r31, r19
 236:	a0 f4       	brcc	.+40     	; 0x260 <__stack+0x1>
 238:	2e 1b       	sub	r18, r30
 23a:	3f 0b       	sbc	r19, r31
 23c:	28 17       	cp	r18, r24
 23e:	39 07       	cpc	r19, r25
 240:	78 f0       	brcs	.+30     	; 0x260 <__stack+0x1>
 242:	ac 01       	movw	r20, r24
 244:	4e 5f       	subi	r20, 0xFE	; 254
 246:	5f 4f       	sbci	r21, 0xFF	; 255
 248:	24 17       	cp	r18, r20
 24a:	35 07       	cpc	r19, r21
 24c:	48 f0       	brcs	.+18     	; 0x260 <__stack+0x1>
 24e:	4e 0f       	add	r20, r30
 250:	5f 1f       	adc	r21, r31
 252:	50 93 72 00 	sts	0x0072, r21	; 0x800072 <__brkval+0x1>
 256:	40 93 71 00 	sts	0x0071, r20	; 0x800071 <__brkval>
 25a:	81 93       	st	Z+, r24
 25c:	91 93       	st	Z+, r25
 25e:	9f cf       	rjmp	.-194    	; 0x19e <malloc+0x70>
 260:	f0 e0       	ldi	r31, 0x00	; 0
 262:	e0 e0       	ldi	r30, 0x00	; 0
 264:	9c cf       	rjmp	.-200    	; 0x19e <malloc+0x70>

00000266 <free>:
free():
 266:	cf 93       	push	r28
 268:	df 93       	push	r29
 26a:	00 97       	sbiw	r24, 0x00	; 0
 26c:	e9 f0       	breq	.+58     	; 0x2a8 <free+0x42>
 26e:	fc 01       	movw	r30, r24
 270:	32 97       	sbiw	r30, 0x02	; 2
 272:	13 82       	std	Z+3, r1	; 0x03
 274:	12 82       	std	Z+2, r1	; 0x02
 276:	a0 91 73 00 	lds	r26, 0x0073	; 0x800073 <__flp>
 27a:	b0 91 74 00 	lds	r27, 0x0074	; 0x800074 <__flp+0x1>
 27e:	ed 01       	movw	r28, r26
 280:	30 e0       	ldi	r19, 0x00	; 0
 282:	20 e0       	ldi	r18, 0x00	; 0
 284:	10 97       	sbiw	r26, 0x00	; 0
 286:	a1 f4       	brne	.+40     	; 0x2b0 <free+0x4a>
 288:	20 81       	ld	r18, Z
 28a:	31 81       	ldd	r19, Z+1	; 0x01
 28c:	82 0f       	add	r24, r18
 28e:	93 1f       	adc	r25, r19
 290:	20 91 71 00 	lds	r18, 0x0071	; 0x800071 <__brkval>
 294:	30 91 72 00 	lds	r19, 0x0072	; 0x800072 <__brkval+0x1>
 298:	28 17       	cp	r18, r24
 29a:	39 07       	cpc	r19, r25
 29c:	09 f0       	breq	.+2      	; 0x2a0 <free+0x3a>
 29e:	61 c0       	rjmp	.+194    	; 0x362 <free+0xfc>
 2a0:	f0 93 72 00 	sts	0x0072, r31	; 0x800072 <__brkval+0x1>
 2a4:	e0 93 71 00 	sts	0x0071, r30	; 0x800071 <__brkval>
 2a8:	df 91       	pop	r29
 2aa:	cf 91       	pop	r28
 2ac:	08 95       	ret
 2ae:	ea 01       	movw	r28, r20
 2b0:	ce 17       	cp	r28, r30
 2b2:	df 07       	cpc	r29, r31
 2b4:	e8 f5       	brcc	.+122    	; 0x330 <free+0xca>
 2b6:	4a 81       	ldd	r20, Y+2	; 0x02
 2b8:	5b 81       	ldd	r21, Y+3	; 0x03
 2ba:	9e 01       	movw	r18, r28
 2bc:	41 15       	cp	r20, r1
 2be:	51 05       	cpc	r21, r1
 2c0:	b1 f7       	brne	.-20     	; 0x2ae <free+0x48>
 2c2:	e9 01       	movw	r28, r18
 2c4:	fb 83       	std	Y+3, r31	; 0x03
 2c6:	ea 83       	std	Y+2, r30	; 0x02
 2c8:	49 91       	ld	r20, Y+
 2ca:	59 91       	ld	r21, Y+
 2cc:	c4 0f       	add	r28, r20
 2ce:	d5 1f       	adc	r29, r21
 2d0:	ec 17       	cp	r30, r28
 2d2:	fd 07       	cpc	r31, r29
 2d4:	61 f4       	brne	.+24     	; 0x2ee <free+0x88>
 2d6:	80 81       	ld	r24, Z
 2d8:	91 81       	ldd	r25, Z+1	; 0x01
 2da:	02 96       	adiw	r24, 0x02	; 2
 2dc:	84 0f       	add	r24, r20
 2de:	95 1f       	adc	r25, r21
 2e0:	e9 01       	movw	r28, r18
 2e2:	99 83       	std	Y+1, r25	; 0x01
 2e4:	88 83       	st	Y, r24
 2e6:	82 81       	ldd	r24, Z+2	; 0x02
 2e8:	93 81       	ldd	r25, Z+3	; 0x03
 2ea:	9b 83       	std	Y+3, r25	; 0x03
 2ec:	8a 83       	std	Y+2, r24	; 0x02
 2ee:	f0 e0       	ldi	r31, 0x00	; 0
 2f0:	e0 e0       	ldi	r30, 0x00	; 0
 2f2:	12 96       	adiw	r26, 0x02	; 2
 2f4:	8d 91       	ld	r24, X+
 2f6:	9c 91       	ld	r25, X
 2f8:	13 97       	sbiw	r26, 0x03	; 3
 2fa:	00 97       	sbiw	r24, 0x00	; 0
 2fc:	b9 f5       	brne	.+110    	; 0x36c <free+0x106>
 2fe:	2d 91       	ld	r18, X+
 300:	3c 91       	ld	r19, X
 302:	11 97       	sbiw	r26, 0x01	; 1
 304:	cd 01       	movw	r24, r26
 306:	02 96       	adiw	r24, 0x02	; 2
 308:	82 0f       	add	r24, r18
 30a:	93 1f       	adc	r25, r19
 30c:	20 91 71 00 	lds	r18, 0x0071	; 0x800071 <__brkval>
 310:	30 91 72 00 	lds	r19, 0x0072	; 0x800072 <__brkval+0x1>
 314:	28 17       	cp	r18, r24
 316:	39 07       	cpc	r19, r25
 318:	39 f6       	brne	.-114    	; 0x2a8 <free+0x42>
 31a:	30 97       	sbiw	r30, 0x00	; 0
 31c:	51 f5       	brne	.+84     	; 0x372 <free+0x10c>
 31e:	10 92 74 00 	sts	0x0074, r1	; 0x800074 <__flp+0x1>
 322:	10 92 73 00 	sts	0x0073, r1	; 0x800073 <__flp>
 326:	b0 93 72 00 	sts	0x0072, r27	; 0x800072 <__brkval+0x1>
 32a:	a0 93 71 00 	sts	0x0071, r26	; 0x800071 <__brkval>
 32e:	bc cf       	rjmp	.-136    	; 0x2a8 <free+0x42>
 330:	d3 83       	std	Z+3, r29	; 0x03
 332:	c2 83       	std	Z+2, r28	; 0x02
 334:	40 81       	ld	r20, Z
 336:	51 81       	ldd	r21, Z+1	; 0x01
 338:	84 0f       	add	r24, r20
 33a:	95 1f       	adc	r25, r21
 33c:	c8 17       	cp	r28, r24
 33e:	d9 07       	cpc	r29, r25
 340:	61 f4       	brne	.+24     	; 0x35a <free+0xf4>
 342:	4e 5f       	subi	r20, 0xFE	; 254
 344:	5f 4f       	sbci	r21, 0xFF	; 255
 346:	88 81       	ld	r24, Y
 348:	99 81       	ldd	r25, Y+1	; 0x01
 34a:	48 0f       	add	r20, r24
 34c:	59 1f       	adc	r21, r25
 34e:	51 83       	std	Z+1, r21	; 0x01
 350:	40 83       	st	Z, r20
 352:	8a 81       	ldd	r24, Y+2	; 0x02
 354:	9b 81       	ldd	r25, Y+3	; 0x03
 356:	93 83       	std	Z+3, r25	; 0x03
 358:	82 83       	std	Z+2, r24	; 0x02
 35a:	21 15       	cp	r18, r1
 35c:	31 05       	cpc	r19, r1
 35e:	09 f0       	breq	.+2      	; 0x362 <free+0xfc>
 360:	b0 cf       	rjmp	.-160    	; 0x2c2 <free+0x5c>
 362:	f0 93 74 00 	sts	0x0074, r31	; 0x800074 <__flp+0x1>
 366:	e0 93 73 00 	sts	0x0073, r30	; 0x800073 <__flp>
 36a:	9e cf       	rjmp	.-196    	; 0x2a8 <free+0x42>
 36c:	fd 01       	movw	r30, r26
 36e:	dc 01       	movw	r26, r24
 370:	c0 cf       	rjmp	.-128    	; 0x2f2 <free+0x8c>
 372:	13 82       	std	Z+3, r1	; 0x03
 374:	12 82       	std	Z+2, r1	; 0x02
 376:	d7 cf       	rjmp	.-82     	; 0x326 <free+0xc0>

00000378 <_exit>:
exit():
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2278
 378:	f8 94       	cli

0000037a <__stop_program>:
__stop_program():
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2280
 37a:	ff cf       	rjmp	.-2      	; 0x37a <__stop_program>

And for that code (246B) :

uint8_t * send = NULL;

void Function(int val)
  {
     
      send = (uint8_t*) malloc((val) * sizeof(uint8_t));
      send[3] = val;
  }

void setup() {}

void loop() {
  Function(5);
}

I get :


Disassembly of section .text:

00000000 <__vectors>:
__vectors():
   0:	10 c0       	rjmp	.+32     	; 0x22 <__ctors_end>
   2:	1f c0       	rjmp	.+62     	; 0x42 <__bad_interrupt>
   4:	1e c0       	rjmp	.+60     	; 0x42 <__bad_interrupt>
   6:	1d c0       	rjmp	.+58     	; 0x42 <__bad_interrupt>
   8:	1c c0       	rjmp	.+56     	; 0x42 <__bad_interrupt>
   a:	1b c0       	rjmp	.+54     	; 0x42 <__bad_interrupt>
   c:	1a c0       	rjmp	.+52     	; 0x42 <__bad_interrupt>
   e:	19 c0       	rjmp	.+50     	; 0x42 <__bad_interrupt>
  10:	18 c0       	rjmp	.+48     	; 0x42 <__bad_interrupt>
  12:	17 c0       	rjmp	.+46     	; 0x42 <__bad_interrupt>
  14:	16 c0       	rjmp	.+44     	; 0x42 <__bad_interrupt>
  16:	16 c0       	rjmp	.+44     	; 0x44 <__vector_11>
  18:	14 c0       	rjmp	.+40     	; 0x42 <__bad_interrupt>
  1a:	13 c0       	rjmp	.+38     	; 0x42 <__bad_interrupt>
  1c:	12 c0       	rjmp	.+36     	; 0x42 <__bad_interrupt>
  1e:	11 c0       	rjmp	.+34     	; 0x42 <__bad_interrupt>
  20:	10 c0       	rjmp	.+32     	; 0x42 <__bad_interrupt>

00000022 <__ctors_end>:
__trampolines_start():
  22:	11 24       	eor	r1, r1
  24:	1f be       	out	0x3f, r1	; 63
  26:	cf e5       	ldi	r28, 0x5F	; 95
  28:	d2 e0       	ldi	r29, 0x02	; 2
  2a:	de bf       	out	0x3e, r29	; 62
  2c:	cd bf       	out	0x3d, r28	; 61

0000002e <__do_clear_bss>:
__do_clear_bss():
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2441
  2e:	20 e0       	ldi	r18, 0x00	; 0
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2442
  30:	a0 e6       	ldi	r26, 0x60	; 96
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2443
  32:	b0 e0       	ldi	r27, 0x00	; 0
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2444
  34:	01 c0       	rjmp	.+2      	; 0x38 <.do_clear_bss_start>

00000036 <.do_clear_bss_loop>:
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2446
  36:	1d 92       	st	X+, r1

00000038 <.do_clear_bss_start>:
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2448
  38:	a9 36       	cpi	r26, 0x69	; 105
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2449
  3a:	b2 07       	cpc	r27, r18
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2450
  3c:	e1 f7       	brne	.-8      	; 0x36 <.do_clear_bss_loop>
.do_clear_bss_start():
  3e:	4c d0       	rcall	.+152    	; 0xd8 <main>
  40:	58 c0       	rjmp	.+176    	; 0xf2 <_exit>

00000042 <__bad_interrupt>:
__vector_1():
  42:	de cf       	rjmp	.-68     	; 0x0 <__vectors>

00000044 <__vector_11>:
__vector_11():
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:308
      #error "cannot find Millis() timer overflow vector"
    #endif
  #else
    #error "Millis() timer not defined!"
  #endif
  {
  44:	1f 92       	push	r1
  46:	0f 92       	push	r0
  48:	0f b6       	in	r0, 0x3f	; 63
  4a:	0f 92       	push	r0
  4c:	11 24       	eor	r1, r1
  4e:	2f 93       	push	r18
  50:	3f 93       	push	r19
  52:	8f 93       	push	r24
  54:	9f 93       	push	r25
  56:	af 93       	push	r26
  58:	bf 93       	push	r27
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:311
    // copy these to local variables so they can be stored in registers
    // (volatile variables must be read from memory on every access)
    unsigned long m = millis_timer_millis;
  5a:	80 91 65 00 	lds	r24, 0x0065	; 0x800065 <millis_timer_millis>
  5e:	90 91 66 00 	lds	r25, 0x0066	; 0x800066 <millis_timer_millis+0x1>
  62:	a0 91 67 00 	lds	r26, 0x0067	; 0x800067 <millis_timer_millis+0x2>
  66:	b0 91 68 00 	lds	r27, 0x0068	; 0x800068 <millis_timer_millis+0x3>
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:312
    unsigned char f = millis_timer_fract;
  6a:	30 91 64 00 	lds	r19, 0x0064	; 0x800064 <millis_timer_fract>
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:319
    static unsigned char correct_exact = 0;     // rollover intended
    if (++correct_exact < CORRECT_EXACT_MANY) {
      ++f;
    }
#endif
    f += FRACT_INC;
  6e:	26 e0       	ldi	r18, 0x06	; 6
  70:	23 0f       	add	r18, r19
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:321

    if (f >= FRACT_MAX)
  72:	2d 37       	cpi	r18, 0x7D	; 125
  74:	68 f1       	brcs	.+90     	; 0xd0 <__vector_11+0x8c>
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:323
    {
      f -= FRACT_MAX;
  76:	29 e8       	ldi	r18, 0x89	; 137
  78:	23 0f       	add	r18, r19
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:324
      m += MILLIS_INC + 1;
  7a:	03 96       	adiw	r24, 0x03	; 3
  7c:	a1 1d       	adc	r26, r1
  7e:	b1 1d       	adc	r27, r1
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:331
    else
    {
      m += MILLIS_INC;
    }

    millis_timer_fract = f;
  80:	20 93 64 00 	sts	0x0064, r18	; 0x800064 <millis_timer_fract>
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:332
    millis_timer_millis = m;
  84:	80 93 65 00 	sts	0x0065, r24	; 0x800065 <millis_timer_millis>
  88:	90 93 66 00 	sts	0x0066, r25	; 0x800066 <millis_timer_millis+0x1>
  8c:	a0 93 67 00 	sts	0x0067, r26	; 0x800067 <millis_timer_millis+0x2>
  90:	b0 93 68 00 	sts	0x0068, r27	; 0x800068 <millis_timer_millis+0x3>
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:334
#ifndef CORRECT_EXACT_MICROS
    millis_timer_overflow_count++;
  94:	80 91 60 00 	lds	r24, 0x0060	; 0x800060 <__DATA_REGION_ORIGIN__>
  98:	90 91 61 00 	lds	r25, 0x0061	; 0x800061 <__DATA_REGION_ORIGIN__+0x1>
  9c:	a0 91 62 00 	lds	r26, 0x0062	; 0x800062 <__DATA_REGION_ORIGIN__+0x2>
  a0:	b0 91 63 00 	lds	r27, 0x0063	; 0x800063 <__DATA_REGION_ORIGIN__+0x3>
  a4:	01 96       	adiw	r24, 0x01	; 1
  a6:	a1 1d       	adc	r26, r1
  a8:	b1 1d       	adc	r27, r1
  aa:	80 93 60 00 	sts	0x0060, r24	; 0x800060 <__DATA_REGION_ORIGIN__>
  ae:	90 93 61 00 	sts	0x0061, r25	; 0x800061 <__DATA_REGION_ORIGIN__+0x1>
  b2:	a0 93 62 00 	sts	0x0062, r26	; 0x800062 <__DATA_REGION_ORIGIN__+0x2>
  b6:	b0 93 63 00 	sts	0x0063, r27	; 0x800063 <__DATA_REGION_ORIGIN__+0x3>
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:336
#endif
  }
  ba:	bf 91       	pop	r27
  bc:	af 91       	pop	r26
  be:	9f 91       	pop	r25
  c0:	8f 91       	pop	r24
  c2:	3f 91       	pop	r19
  c4:	2f 91       	pop	r18
  c6:	0f 90       	pop	r0
  c8:	0f be       	out	0x3f, r0	; 63
  ca:	0f 90       	pop	r0
  cc:	1f 90       	pop	r1
  ce:	18 95       	reti
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:328
      f -= FRACT_MAX;
      m += MILLIS_INC + 1;
    }
    else
    {
      m += MILLIS_INC;
  d0:	02 96       	adiw	r24, 0x02	; 2
  d2:	a1 1d       	adc	r26, r1
  d4:	b1 1d       	adc	r27, r1
  d6:	d4 cf       	rjmp	.-88     	; 0x80 <__vector_11+0x3c>

000000d8 <main>:
main():
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:1138
*/

  // Use the Millis Timer for fast PWM (unless it doesn't have an output).
  #if (TIMER_TO_USE_FOR_MILLIS == 0)
    #if defined(WGM01) // if Timer0 has PWM
      TCCR0A = (1<<WGM01) | (1<<WGM00);
  d8:	83 e0       	ldi	r24, 0x03	; 3
  da:	80 bf       	out	0x30, r24	; 48
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:1141
    #endif
    #if defined(TCCR0B) //The x61 has a wacky Timer0!
      TCCR0B = (MillisTimer_Prescale_Index << CS00);
  dc:	83 bf       	out	0x33, r24	; 51
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:1162
    TCCR1A = 1<<WGM10;
    TCCR1B = (1<<WGM12) | (MillisTimer_Prescale_Index << CS10);
  #endif

  // this needs to be called before setup() or some functions won't work there
  sei();
  de:	78 94       	sei
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:1169
  #ifndef DISABLEMILLIS
    // Enable the overflow interrupt (this is the basic system tic-toc for millis)
    #if defined(TIMSK) && defined(TOIE0) && (TIMER_TO_USE_FOR_MILLIS == 0)
      sbi(TIMSK, TOIE0);
    #elif defined(TIMSK0) && defined(TOIE0) && (TIMER_TO_USE_FOR_MILLIS == 0)
      sbi(TIMSK0, TOIE0);
  e0:	99 b7       	in	r25, 0x39	; 57
  e2:	91 60       	ori	r25, 0x01	; 1
  e4:	99 bf       	out	0x39, r25	; 57
initToneTimerInternal():
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:972
    #elif (TIMER_TO_USE_FOR_TONE == 1 ) && defined(__AVR_ATtinyX7__)
      TCCR1A = (1<<COM1A1)|(1<<COM1B1)|(1<<WGM10);
      TCCR1B = (ToneTimer_Prescale_Index << CS10);
    #elif (TIMER_TO_USE_FOR_TONE == 1) // x4, x8, x313,
      // Use the Tone Timer for phase correct PWM
      TCCR1A = (1<<WGM10);
  e6:	91 e0       	ldi	r25, 0x01	; 1
  e8:	9f bd       	out	0x2f, r25	; 47
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:973
      TCCR1B = (0<<WGM12) | (0<<WGM13) | (ToneTimer_Prescale_Index << CS10); //set the clock
  ea:	8e bd       	out	0x2e, r24	; 46
main():
\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring.c:1214
  #if defined( INITIALIZE_ANALOG_TO_DIGITAL_CONVERTER ) && INITIALIZE_ANALOG_TO_DIGITAL_CONVERTER
    #if defined(ADCSRA)
      // set a2d prescale factor
      // ADCSRA = (ADCSRA & ~((1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0))) | (ADC_ARDUINO_PRESCALER << ADPS0) | (1<<ADEN);
      // dude, this is being called on startup. We know that ADCSRA is 0! Why add a RMW cycle?!
      ADCSRA = (ADC_ARDUINO_PRESCALER << ADPS0) | (1<<ADEN);
  ec:	86 e8       	ldi	r24, 0x86	; 134
  ee:	86 b9       	out	0x06, r24	; 6
  f0:	ff cf       	rjmp	.-2      	; 0xf0 <main+0x18>

000000f2 <_exit>:
exit():
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2278
  f2:	f8 94       	cli

000000f4 <__stop_program>:
__stop_program():
/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr25/libgcc/../../../../gcc/libgcc/config/avr/lib1funcs.S:2280
  f4:	ff cf       	rjmp	.-2      	; 0xf4 <__stop_program>

In short word, in the 246B, there is no sketch : no call for malloc, no function, only Attiny Core.
Could someone check for it, looks like a bug, or some big mistake in my code.

Get it :wink:
My meaning was i have some basic asm knowledge to read asm code

in one case (when there is the if) you are alocating the buffer only once and always write val at the third position of the same buffer

in the other case (no if) you keep allocating the buffer over and over again without freeing the memory (so will crash at some point) and you write the val at various places in RAM since the buffer changes.

probably the optimiser picks that up - it's not the same code.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.